mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex
@ 2026-09-19  8:55 Abdelnasser Hussein
  2026-09-19  9:31 ` Joshua Crofts
  2026-09-19 10:44 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Abdelnasser Hussein @ 2026-09-19  8:55 UTC (permalink / raw)
  To: jic23, gregkh, nuno.sa, Michael.Hennerich
  Cc: dlechner, andy, linux, linux-iio, linux-staging, linux-kernel,
	joshua.crofts1, Abdelnasser Hussein

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.

Add the existing chip->lock guard to these functions to serialize
access and prevent race conditions.

Suggested-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>
---
 drivers/staging/iio/adc/ad7816.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index f76f0215119a..d8f4b1f79e2a 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -143,6 +143,7 @@ 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 +208,7 @@ static ssize_t ad7816_store_channel(struct device *dev,
 		return -EINVAL;
 	}
 
+	guard(mutex)(&chip->lock);
 	chip->channel_id = data;
 
 	return len;
-- 
2.54.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex
  2026-09-19  8:55 [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex Abdelnasser Hussein
@ 2026-09-19  9:31 ` Joshua Crofts
  2026-09-19 10:44 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Joshua Crofts @ 2026-09-19  9:31 UTC (permalink / raw)
  To: Abdelnasser Hussein
  Cc: jic23, gregkh, nuno.sa, Michael.Hennerich, dlechner, andy, linux,
	linux-iio, linux-staging, linux-kernel

On Sat, 19 Sep 2026 11:55:13 +0300
Abdelnasser Hussein <abdelnasserhussein11@gmail.com> wrote:

...

> @@ -143,6 +143,7 @@ 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);

+ Blank line.

>  	if (strcmp(buf, "full") == 0) {
>  		gpiod_set_value(chip->rdwr_pin, 1);
>  		chip->mode = AD7816_FULL;
> @@ -207,6 +208,7 @@ static ssize_t ad7816_store_channel(struct device *dev,
>  		return -EINVAL;
>  	}
>  
> +	guard(mutex)(&chip->lock);

+ Blank line.

>  	chip->channel_id = data;

With these issues addressed,

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex
  2026-09-19  8:55 [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex Abdelnasser Hussein
  2026-09-19  9:31 ` Joshua Crofts
@ 2026-09-19 10:44 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2026-09-19 10:44 UTC (permalink / raw)
  To: Abdelnasser Hussein
  Cc: jic23, gregkh, nuno.sa, Michael.Hennerich, dlechner, andy, linux,
	linux-iio, linux-staging, linux-kernel, joshua.crofts1

On Sat, Sep 19, 2026 at 11:55:13AM +0300, Abdelnasser Hussein 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.
> 
> Add the existing chip->lock guard to these functions to serialize
> access and prevent race conditions.
> 
> Suggested-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@gmail.com>

Add a Fixes tag.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-19 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19  8:55 [PATCH] staging: iio: adc: ad7816: Protect sysfs attributes with mutex Abdelnasser Hussein
2026-09-19  9:31 ` Joshua Crofts
2026-09-19 10:44 ` Dan Carpenter

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®