mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: tsys02d: Fix state desynchronization on resolution write error
@ 2026-09-07  8:53 Salah Triki
  2026-09-07 14:50 ` Joshua Crofts
  0 siblings, 1 reply; 3+ messages in thread
From: Salah Triki @ 2026-09-07  8:53 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, Salah Triki

In tsys02d_write_raw(), dev_data->res_index is updated before checking
the return value of ms_sensors_write_resolution(). If the hardware I2C
write operation fails, dev_data->res_index remains updated with the
new index despite the physical sensor remaining in its previous state.

This leads to a state desynchronization where subsequent reads via
tsys02d_read_raw() return an incorrect sampling frequency.

Fix this by performing the I2C write first and updating dev_data->res_index
only if ms_sensors_write_resolution() succeeds.

Fixes: 53bf4d067d51 ("Add tsys02d meas-spec driver support")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/iio/temperature/tsys02d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c
index 3ef72347456e..f50426beacdd 100644
--- a/drivers/iio/temperature/tsys02d.c
+++ b/drivers/iio/temperature/tsys02d.c
@@ -73,8 +73,9 @@ static int tsys02d_write_raw(struct iio_dev *indio_dev,
 		if (i < 0)
 			return -EINVAL;
 		mutex_lock(&dev_data->lock);
-		dev_data->res_index = i;
 		ret = ms_sensors_write_resolution(dev_data, i);
+		if (!ret)
+			dev_data->res_index = i;
 		mutex_unlock(&dev_data->lock);
 
 		return ret;
-- 
2.43.0


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

end of thread, other threads:[~2026-09-08 10:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-07  8:53 [PATCH] iio: temperature: tsys02d: Fix state desynchronization on resolution write error Salah Triki
2026-09-07 14:50 ` Joshua Crofts
2026-09-08 10:32   ` 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®