[PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control

From: Joshua Crofts

Date: Tue Apr 14 2026 - 05:16:44 EST


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@xxxxxxxxx>
---
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