Re: [PATCH v3] staging: iio: adc: ad7816: Protect sysfs attributes with mutex

From: Jonathan Cameron

Date: Sun Sep 27 2026 - 15:05:41 EST


On Wed, 23 Sep 2026 14:07:45 +0300
Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx> wrote:

> The sysfs store functions modify driver state that is critical during
> SPI transactions. ad7816_store_mode toggles hardware GPIO pins, while
> ad7816_store_channel updates the internal software state
> (chip->channel_id).
>
> If these are modified concurrently by userspace while an SPI transfer
> is in progress, it could corrupt the hardware transaction or cause the
> driver to communicate with the wrong channel.
>
> Add the existing chip->lock guard to these functions to serialize
> access and prevent these race conditions.
>
> Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> Suggested-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> Reviewed-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
Applied to the testing branch of iio.git.

Thanks,

Jonathan