mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: pressure: dps310: read the first temperature in probe
@ 2026-11-19 19:08 Rupesh Majhi
  2026-11-19 19:33 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Rupesh Majhi @ 2026-11-19 19:08 UTC (permalink / raw)
  To: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá,
	Rupesh Majhi
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Arnav Kapoor

The first temperature read is in dps310_fifo_interval() instead of
probe. That function is called with data->lock held and takes it
again, so enabling the buffer without a trigger deadlocks.

Move the read to probe.

Fixes: 903941a9b06a ("iio: pressure: dps310: don't wait for new temperature in trigger handler")
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
My v2 was on fixes-togreg and its probe hunk does not match testing,
sorry for the trouble.

Based on iio togreg. Same change as the diff in [1], fine to squash
into 903941a9b06a instead.

Tested on a DPS310 on a BeagleBone Black: enabling the buffer without
a trigger works.

[1] https://lore.kernel.org/linux-iio/20261117110735.46400-1-zoone.rupert@gmail.com/

Cc: Arnav Kapoor <kapoorarnav43@gmail.com>
Cc: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>

 drivers/iio/pressure/dps310.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 9b52cbc2372a..ebfaa67a6b91 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -1058,16 +1058,9 @@ static unsigned int dps310_fifo_interval(struct dps310_data *data,
 {
 	unsigned int drain_interval_ms, fill_ms, want_ms;
 	int scan_rate;
-	int rc;
 
 	fill_ms = MSEC_PER_SEC * DPS310_FIFO_DEPTH / (prs_rate + tmp_rate);
 
-	/* Pressure compensation needs a temperature from the start */
-	scoped_guard(mutex, &data->lock)
-		rc = dps310_read_temp_raw_locked(data);
-	if (rc)
-		return rc;
-
 	/*
 	 * There is no hardware watermark, so take it as the number of scans
 	 * the user will wait for and drain at that rate. Scans come from
@@ -1478,6 +1471,12 @@ static int dps310_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	/* Pressure compensation needs a temperature from the start */
+	scoped_guard(mutex, &data->lock)
+		rc = dps310_read_temp_raw_locked(data);
+	if (rc)
+		return rc;
+
 	/*
 	 * The device measures continuously in background mode, so a triggered
 	 * capture is just a read of the latest results. The setup ops run the

base-commit: 903941a9b06ae445c70646ab061b604c2dea17d3
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: pressure: dps310: read the first temperature in probe
  2026-11-19 19:08 [PATCH] iio: pressure: dps310: read the first temperature in probe Rupesh Majhi
@ 2026-11-19 19:33 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-11-19 19:33 UTC (permalink / raw)
  To: Rupesh Majhi
  Cc: Andy Shevchenko, David Lechner, Eddie James, Jonathan Cameron,
	Nuno Sá,
	Jonathan Cameron, linux-iio, linux-kernel, Arnav Kapoor

On Thu, Nov 19, 2026 at 09:08:27PM +0200, Rupesh Majhi wrote:
> The first temperature read is in dps310_fifo_interval() instead of
> probe. That function is called with data->lock held and takes it
> again, so enabling the buffer without a trigger deadlocks.
> 
> Move the read to probe.

...

> +	/* Pressure compensation needs a temperature from the start */
> +	scoped_guard(mutex, &data->lock)
> +		rc = dps310_read_temp_raw_locked(data);
> +	if (rc)
> +		return rc;

While at it, making branch in scope

	scoped_guard(mutex, &data->lock) {
		rc = dps310_read_temp_raw_locked(data);
		if (rc)
			return rc;
	}

helps to avoid potential issues later on.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 19:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 19:08 [PATCH] iio: pressure: dps310: read the first temperature in probe Rupesh Majhi
2026-11-19 19:33 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®