Re: [PATCH v6 2/3] staging: iio: adc: ad7816: Serialize SPI read operations

From: Andy Shevchenko

Date: Sun Sep 13 2026 - 04:20:59 EST


On Sat, Sep 12, 2026 at 04:25:16PM +0300, Abdelnasser Hussein wrote:
> The ad7816_spi_read() function performs a sequence of GPIO state
> changes followed by an SPI transfer. If multiple read operations
> occur simultaneously, the GPIO state could be changed by one thread
> while another is in the middle of a read. This leads to a race
> condition where the sensor state is disrupted.
>
> Introduce a mutex to serialize the read sequence, ensuring that the
> GPIO toggling and the SPI transfer are treated as a single atomic
> operation.

...

> struct ad7816_chip_info {

> u8 oti_data[AD7816_CS_MAX + 1];
> u8 channel_id; /* 0 always be temperature */
> u8 mode;
> + struct mutex lock; /* protect device state during SPI transfers */
> };

Is `pahole` happy with the chosen layout?

--
With Best Regards,
Andy Shevchenko