public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Joshua Crofts <joshua.crofts1@gmail.com>
To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
	gregkh@linuxfoundation.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	linux-iio@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Joshua Crofts <joshua.crofts1@gmail.com>
Subject: [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control
Date: Tue, 14 Apr 2026 09:12:50 +0000	[thread overview]
Message-ID: <20260414091250.1295-4-joshua.crofts1@gmail.com> (raw)
In-Reply-To: <20260414091250.1295-1-joshua.crofts1@gmail.com>

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


  parent reply	other threads:[~2026-04-14  9:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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: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:29   ` Dan Carpenter
2026-04-14  9:12 ` Joshua Crofts [this message]
2026-04-14  9:36   ` [PATCH 3/3] iio: frequency: ad9834: add mutex_lock() when reading st->control Dan Carpenter
2026-04-14  9:44     ` Joshua Crofts

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=20260414091250.1295-4-joshua.crofts1@gmail.com \
    --to=joshua.crofts1@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --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