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

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.