Re: [PATCH v3] iio: temperature: tsys02d: Fix state desynchronization on resolution write error

From: Jonathan Cameron

Date: Sun Oct 18 2026 - 18:54:12 EST


On Mon, 5 Oct 2026 16:19:50 +0200
Joshua Crofts <joshua.crofts1@xxxxxxxxx> wrote:

> On Mon, 5 Oct 2026 14:20:02 +0100
> Salah Triki <salah.triki@xxxxxxxxx> wrote:
>
> > 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 handling the error path first, updating dev_data->res_index
> > only on success, and using guard(mutex) to clean up locking.
> >
> > This was found through manual code review.
> >
> > Fixes: 53bf4d067d51 ("Add tsys02d meas-spec driver support")
> > Signed-off-by: Salah Triki <salah.triki@xxxxxxxxx>
> > ---
>
> Makes sense.
>
> Reviewed-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
>
I'll take this one the slow path given it is a fix for an error
case we don't really expect to see.

Applied to the testing branch of iio.git.

Thanks,

Jonathan