Re: [PATCH v7 2/3] staging: iio: adc: ad7816: Serialize SPI operations
From: Joshua Crofts
Date: Tue Sep 15 2026 - 09:17:02 EST
On Tue, 15 Sep 2026 06:39:34 -0500
"Maxwell Doose" <maxwell@xxxxxxxxxxx> wrote:
> On Tue Sep 15, 2026 at 2:59 AM CDT
> Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx> wrote:
>
> > The ad7816_spi_read() and ad7816_spi_write() functions perform a
> > sequence of GPIO state changes followed by an SPI transfer. If multiple
> > operations occur simultaneously, the GPIO state could be changed by one
> > thread while another is in the middle of a transfer, leading to a race
> > condition.
> >
> > Introduce a mutex to serialize the operations, ensuring that the GPIO
> > toggling and the SPI transfer are treated as a single atomic operation.
> > The mutex is placed right after the pointers in the device state
> > structure to avoid padding holes.
> >
> > Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
> > ---
> > drivers/staging/iio/adc/ad7816.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> ...
> > @@ -47,6 +49,7 @@ struct ad7816_chip_info {
> > struct gpio_desc *rdwr_pin;
> > struct gpio_desc *convert_pin;
> > struct gpio_desc *busy_pin;
> > + struct mutex lock; /* protect device state during SPI transfers */
>
> I'm a little on the fence about the comment but if it satisfies
> checkpatch then thats one less patch later.
It's perfectly fine to comment like this, especially since this seems to
be the style the driver uses.
--
Kind regards,
Joshua Crofts