Re: [PATCH v5 5/6] iio: dac: ad5504: introduce local lock to protect state and spi transfers

From: Andy Shevchenko

Date: Fri Aug 21 2026 - 09:31:39 EST


On Fri, Aug 21, 2026 at 06:24:47AM -0400, Taha Ed-Dafili wrote:
> The driver lacks locking, exposing concurrent access to the shared DMA
> SPI buffers, the non-atomic CTRL+NOOP write sequence in powerdown, and
> the pwr_down_mask/pwr_down_mode state variables.
>
> Introduce a mutex via devm_mutex_init() and guard(mutex) at the IIO
> callbacks to serialize access. In read_raw() and write_raw(), scope the
> lock to IIO_CHAN_INFO_RAW only since IIO_CHAN_INFO_SCALE reads vref_mv
> which is immutable after probe.

...

> static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev,

> int ret;
> struct ad5504_state *st = iio_priv(indio_dev);
>
> + guard(mutex)(&st->lock);
> +
> ret = kstrtobool(buf, &pwr_down);
> if (ret)
> return ret;

This part is not needed to be under the mutex. So, first convert the input,
then acquire the lock.

--
With Best Regards,
Andy Shevchenko