iio: temperature: tsys02d: Fix state desynchronization on resolution write error
PATCH 1/1 iio: temperature: tsys02d: Fix state desynchronization on resolution write error
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.
--- drivers/iio/temperature/tsys02d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/temperature/tsys02d.c +2 -1
@@ -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;
Signature · 1 line
2.43.0
Quoted 5 lines · On Mon, 7 Sep 2026 09:53:53 +0100 Salah Triki <[email protected]> wrote:
In
tsys02d_write_raw(),dev_data->res_indexis updated before checking the return value ofms_sensors_write_resolution(). If the hardware I2C write operation fails,dev_data->res_indexremains updated with the new index despite the physical sensor remaining in its previous state.
Quoted 8 lines
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_indexonly ifms_sensors_write_resolution()succeeds.Fixes 53bf4d067d51 ("Add tsys02d meas-spec driver support")Signed-off-by Salah Triki <[email protected]>
Was this found using an LLM or manually?
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 76
Quoted 13 lines
--- drivers/iio/temperature/tsys02d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/temperature/tsys02d.c +0
-1@@ -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;
+ blank line
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 78
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +2
-0ret =ms_sensors_write_resolution (dev_data, i); +if (!ret) + dev_data->res_index = i;
+ blank line
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 81
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +0
-0mutex_unlock (&dev_data->lock);return ret;
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 2 lines · Joshua Crofts
On Mon, 7 Sep 2026 09:53:53 +0100
Salah Triki <[email protected]> wrote:
...
Quoted 11 lines
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 78
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +2
-0ret =ms_sensors_write_resolution (dev_data, i); +if (!ret) + dev_data->res_index = i;+ blank line
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 81
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +0
-0mutex_unlock (&dev_data->lock);return ret;Reviewed-by Joshua Crofts <[email protected]>
Actually we prefer usual pattern — "check for error first". This 'if (!ret)' is confusing.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 12 lines · On Tue, 8 Sep 2026 13:32:44 +0300 Andy Shevchenko…
Quoted 2 lines · Joshua Crofts
On Mon, 7 Sep 2026 09:53:53 +0100
Salah Triki <[email protected]> wrote:...
Quoted 6 lines
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 78
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +2
-0ret =ms_sensors_write_resolution (dev_data, i); +if (!ret) + dev_data->res_index = i;+ blank line
Quoted 9 lines
Quoted 5 lines
drivers/iio/temperature/tsys02d.c static int tsys02d_write_raw(struct iio_dev *indio_dev, · line 81
Quoted 3 lines
drivers/iio/temperature/tsys02d.c +0
-0mutex_unlock (&dev_data->lock);return ret;Reviewed-by Joshua Crofts <[email protected]>Actually we prefer usual pattern — "check for error first". This 'if (!ret)' is confusing.
I'd use a guard so we can just return when the error is seen.