From: Jonathan Cameron <jic23@kernel.org>
To: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
Cc: gregkh@linuxfoundation.org, nuno.sa@analog.com,
Michael.Hennerich@analog.com, dlechner@baylibre.com,
andy@kernel.org, linux@analog.com, linux-iio@vger.kernel.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
joshua.crofts1@gmail.com, error27@gmail.com
Subject: Re: [PATCH v2] staging: iio: adc: ad7816: Protect sysfs attributes with mutex
Date: Mon, 21 Sep 2026 04:49:19 +0100 [thread overview]
Message-ID: <20260921044919.2cc50837@jic23-hlaptop> (raw)
In-Reply-To: <20260920091522.15507-1-abdelnasserhussein11@gmail.com>
On Sun, 20 Sep 2026 12:15:22 +0300
Abdelnasser Hussein <abdelnasserhussein11@gmail.com> wrote:
> The sysfs store functions (ad7816_store_mode and ad7816_store_channel)
> modify the device state and toggle GPIO pins. If accessed concurrently
> by userspace during an ongoing SPI transfer, this could corrupt the
> SPI transaction.
See below. One of them doesn't seem to have that possible affect.
Thanks,
Jonathan
>
> Add the existing chip->lock guard to these functions to serialize
> access and prevent race conditions.
>
> Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
> Suggested-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
> ---
> Changes in v2:
> - Added a blank line after guard(mutex) statements as requested by Joshua.
> - Added Fixes tag as requested by Dan.
> - Collected Reviewed-by tag from Joshua.
>
> drivers/staging/iio/adc/ad7816.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
> index f76f0215119a..2a15d7598abb 100644
> --- a/drivers/staging/iio/adc/ad7816.c
> +++ b/drivers/staging/iio/adc/ad7816.c
> @@ -143,6 +143,8 @@ static ssize_t ad7816_store_mode(struct device *dev,
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct ad7816_chip_info *chip = iio_priv(indio_dev);
>
> + guard(mutex)(&chip->lock);
> +
> if (strcmp(buf, "full") == 0) {
> gpiod_set_value(chip->rdwr_pin, 1);
> chip->mode = AD7816_FULL;
> @@ -207,6 +209,8 @@ static ssize_t ad7816_store_channel(struct device *dev,
> return -EINVAL;
> }
>
> + guard(mutex)(&chip->lock);
This isn't toggling pins or modifying anything on the device state side
of things. So at very least the commit message needs to be expanded to
what this is doing that needs a lock.
> +
> chip->channel_id = data;
>
> return len;
next prev parent reply other threads:[~2026-09-21 3:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 9:15 Abdelnasser Hussein
2026-09-21 3:49 ` Jonathan Cameron [this message]
2026-09-23 6:13 ` kernel test robot
2026-09-23 12:44 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921044919.2cc50837@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=abdelnasserhussein11@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux@analog.com \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®