* [PATCH 1/3] iio: frequency: ad9834: clean up includes
2026-04-14 9:12 [PATCH 0/3] iio: frequency: ad9834: driver cleanup Joshua Crofts
@ 2026-04-14 9:12 ` Joshua Crofts
2026-04-14 9:47 ` Andy Shevchenko
2026-04-14 9:12 ` [PATCH 2/3] iio: frequency: ad9834: change sprintf() to sysfs_emit() Joshua Crofts
2026-04-14 9:12 ` [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control Joshua Crofts
2 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-04-14 9:12 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, gregkh
Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
Joshua Crofts
Clean up includes by removing proxy kernel.h header,
add bitops.h header and order includes for better
readability.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/staging/iio/frequency/ad9834.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index d339d5e8e0..eed4e08920 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -5,19 +5,19 @@
* Copyright 2010-2011 Analog Devices Inc.
*/
+#include <asm/div64.h>
+#include <linux/bitops.h>
#include <linux/clk.h>
-#include <linux/interrupt.h>
-#include <linux/workqueue.h>
#include <linux/device.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/spi/spi.h>
-#include <linux/regulator/consumer.h>
#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
#include <linux/module.h>
-#include <asm/div64.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/sysfs.h>
+#include <linux/workqueue.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] iio: frequency: ad9834: clean up includes
2026-04-14 9:12 ` [PATCH 1/3] iio: frequency: ad9834: clean up includes Joshua Crofts
@ 2026-04-14 9:47 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-04-14 9:47 UTC (permalink / raw)
To: Joshua Crofts
Cc: lars, Michael.Hennerich, jic23, gregkh, dlechner, nuno.sa, andy,
linux-iio, linux-staging, linux-kernel
On Tue, Apr 14, 2026 at 09:12:48AM +0000, Joshua Crofts wrote:
> Clean up includes by removing proxy kernel.h header,
> add bitops.h header and order includes for better
> readability.
...
> +#include <asm/div64.h>
This should go after generic linux/*. In other words, it was originally placed
correctly.
> +#include <linux/bitops.h>
> #include <linux/clk.h>
> -#include <linux/interrupt.h>
> -#include <linux/workqueue.h>
> #include <linux/device.h>
Also check for usage of this one.
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/sysfs.h>
> -#include <linux/list.h>
> -#include <linux/spi/spi.h>
> -#include <linux/regulator/consumer.h>
> #include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/list.h>
> #include <linux/module.h>
> -#include <asm/div64.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/slab.h>
> +#include <linux/spi/spi.h>
> +#include <linux/sysfs.h>
> +#include <linux/workqueue.h>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] iio: frequency: ad9834: change sprintf() to sysfs_emit()
2026-04-14 9:12 [PATCH 0/3] iio: frequency: ad9834: driver cleanup Joshua Crofts
2026-04-14 9:12 ` [PATCH 1/3] iio: frequency: ad9834: clean up includes Joshua Crofts
@ 2026-04-14 9:12 ` Joshua Crofts
2026-04-14 9:29 ` Dan Carpenter
2026-04-14 9:12 ` [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control Joshua Crofts
2 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-04-14 9:12 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, gregkh
Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
Joshua Crofts
Change instances of sprintf() to sysfs_emit() as returning
formatted values to user space should be done using this
function.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/staging/iio/frequency/ad9834.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index eed4e08920..9499e05a73 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -290,7 +290,7 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
else
str = "sine triangle";
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "%s\n", str);
}
static IIO_DEVICE_ATTR(out_altvoltage0_out0_wavetype_available, 0444,
@@ -310,7 +310,7 @@ ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
else
str = "square";
- return sprintf(buf, "%s\n", str);
+ return sysfs_emit(buf, "%s\n", str);
}
static IIO_DEVICE_ATTR(out_altvoltage0_out1_wavetype_available, 0444,
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] iio: frequency: ad9834: change sprintf() to sysfs_emit()
2026-04-14 9:12 ` [PATCH 2/3] iio: frequency: ad9834: change sprintf() to sysfs_emit() Joshua Crofts
@ 2026-04-14 9:29 ` Dan Carpenter
0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2026-04-14 9:29 UTC (permalink / raw)
To: Joshua Crofts
Cc: lars, Michael.Hennerich, jic23, gregkh, dlechner, nuno.sa, andy,
linux-iio, linux-staging, linux-kernel
On Tue, Apr 14, 2026 at 09:12:49AM +0000, Joshua Crofts wrote:
> Change instances of sprintf() to sysfs_emit() as returning
> formatted values to user space should be done using this
> function.
>
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
Someone beat you to it. You're working against an old tree.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control
2026-04-14 9:12 [PATCH 0/3] iio: frequency: ad9834: driver cleanup Joshua Crofts
2026-04-14 9:12 ` [PATCH 1/3] iio: frequency: ad9834: clean up includes Joshua Crofts
2026-04-14 9:12 ` [PATCH 2/3] iio: frequency: ad9834: change sprintf() to sysfs_emit() Joshua Crofts
@ 2026-04-14 9:12 ` Joshua Crofts
2026-04-14 9:36 ` Dan Carpenter
2 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-04-14 9:12 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, gregkh
Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
Joshua Crofts
Add mutex_lock() and mutex_unlock() when reading st->control to
prevent data races as st->control is actively modified by
sysfs _write and _store functions.
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
drivers/staging/iio/frequency/ad9834.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 9499e05a73..33570474c4 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -283,12 +283,14 @@ ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
struct ad9834_state *st = iio_priv(indio_dev);
char *str;
+ mutex_lock(&st->lock);
if (st->devid == ID_AD9833 || st->devid == ID_AD9837)
str = "sine triangle square";
else if (st->control & AD9834_OPBITEN)
str = "sine";
else
str = "sine triangle";
+ mutex_unlock(&st->lock);
return sysfs_emit(buf, "%s\n", str);
}
@@ -305,10 +307,12 @@ ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
struct ad9834_state *st = iio_priv(indio_dev);
char *str;
+ mutex_lock(&st->lock);
if (st->control & AD9834_MODE)
str = "";
else
str = "square";
+ mutex_unlock(&st->lock);
return sysfs_emit(buf, "%s\n", str);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control
2026-04-14 9:12 ` [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control Joshua Crofts
@ 2026-04-14 9:36 ` Dan Carpenter
2026-04-14 9:44 ` Joshua Crofts
0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2026-04-14 9:36 UTC (permalink / raw)
To: Joshua Crofts
Cc: lars, Michael.Hennerich, jic23, gregkh, dlechner, nuno.sa, andy,
linux-iio, linux-staging, linux-kernel
On Tue, Apr 14, 2026 at 09:12:50AM +0000, Joshua Crofts wrote:
> Add mutex_lock() and mutex_unlock() when reading st->control to
> prevent data races as st->control is actively modified by
> sysfs _write and _store functions.
>
> Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
> ---
This doesn't matter in real life. "Oops, the root user tried
really hard to do something stupid and got "square" as the output
a fraction of a milisecond longer than they were supposed to."
Is there a tool which detects and complains about this?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control
2026-04-14 9:36 ` Dan Carpenter
@ 2026-04-14 9:44 ` Joshua Crofts
0 siblings, 0 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-04-14 9:44 UTC (permalink / raw)
To: Dan Carpenter
Cc: lars, Michael.Hennerich, jic23, gregkh, dlechner, nuno.sa, andy,
linux-iio, linux-staging, linux-kernel
On Tue, 14 Apr 2026 at 11:36, Dan Carpenter <error27@gmail.com> wrote:
> This doesn't matter in real life. "Oops, the root user tried
> really hard to do something stupid and got "square" as the output
> a fraction of a milisecond longer than they were supposed to."
>
> Is there a tool which detects and complains about this?
No, no tool complained about it, I honestly just thought it's best practice to
add a mutex_lock() given that st->control is "volatile".
--
Kind regards
CJD
^ permalink raw reply [flat|nested] 8+ messages in thread