[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aLWULUIcYEz3N-Rx@smile.fi.intel.com>
Date: Mon, 1 Sep 2025 15:40:13 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: Mohammad Amin Hosseini <moahmmad.hosseinii@...il.com>,
linux-iio@...r.kernel.org, linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org, gregkh@...uxfoundation.org,
jic23@...nel.org, lars@...afoo.de, Michael.Hennerich@...log.com,
dlechner@...libre.com, nuno.sa@...log.com, andy@...nel.org
Subject: Re: [PATCH v2] staging: iio: adc: ad7816: add mutex to serialize
SPI/GPIO operations
On Mon, Sep 01, 2025 at 01:23:40PM +0300, Dan Carpenter wrote:
> On Mon, Sep 01, 2025 at 10:24:45AM +0330, Mohammad Amin Hosseini wrote:
> > From: mohammad amin hosseini <moahmmad.hosseinii@...il.com>
> >
> > The ad7816 driver was accessing SPI and GPIO lines without
> > synchronization, which could lead to race conditions when accessed
> > concurrently from multiple contexts. This might result in corrupted
> > readings or inconsistent GPIO states.
> >
> > Introduce an io_lock mutex in the driver structure to serialize:
> > - SPI transactions in ad7816_spi_read() and ad7816_spi_write()
> > - GPIO pin toggling sequences
> > - Updates to device state via sysfs store functions (mode, channel, oti)
> >
> > The mutex ensures proper mutual exclusion and prevents race
> > conditions under concurrent access.
...
> > + mutex_lock(&chip->io_lock);
> > chip->channel_id = data;
> > + mutex_unlock(&chip->io_lock);
> > + mutex_lock(&chip->io_lock);
> > chip->oti_data[chip->channel_id] = data;
> > + mutex_unlock(&chip->io_lock);
> I'm not really knowledgeable to review the others, if they are
> required or how the locking is supposed to work. But these aren't
> correct because we're only locking around the writers and not the
> readers so it could still race.
Readers are in spi_write(), or what do you imply by this comment?
I.o.w. I do not see the issue with the idea of locking and how it's
done (I haven't checked all of the details, though).
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists