From: William Breathitt Gray <william.gray@linaro.org>
To: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
William Breathitt Gray <william.gray@linaro.org>
Subject: [PATCH v4 2/5] iio: addac: stx104: Fix race condition when converting analog-to-digital
Date: Tue, 4 Apr 2023 10:11:59 -0400 [thread overview]
Message-ID: <2ae5e40eed5006ca735e4c12181a9ff5ced65547.1680564468.git.william.gray@linaro.org> (raw)
In-Reply-To: <cover.1680564468.git.william.gray@linaro.org>
The ADC conversion procedure requires several device I/O operations
performed in a particular sequence. If stx104_read_raw() is called
concurrently, the ADC conversion procedure could be clobbered. Prevent
such a race condition by utilizing a mutex.
Fixes: 4075a283ae83 ("iio: stx104: Add IIO support for the ADC channels")
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
---
drivers/iio/addac/stx104.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/addac/stx104.c b/drivers/iio/addac/stx104.c
index 4239aafe42fc..8730b79e921c 100644
--- a/drivers/iio/addac/stx104.c
+++ b/drivers/iio/addac/stx104.c
@@ -117,6 +117,8 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
}
+ mutex_lock(&priv->lock);
+
/* select ADC channel */
iowrite8(chan->channel | (chan->channel << 4), ®->achan);
@@ -127,6 +129,8 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
while (ioread8(®->cir_asr) & BIT(7));
*val = ioread16(®->ssr_ad);
+
+ mutex_unlock(&priv->lock);
return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET:
/* get ADC bipolar/unipolar configuration */
--
2.39.2
next prev parent reply other threads:[~2023-04-04 14:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 14:11 [PATCH v4 0/5] Migrate STX104 to the regmap API William Breathitt Gray
2023-04-04 14:11 ` [PATCH v4 1/5] iio: addac: stx104: Fix race condition for stx104_write_raw() William Breathitt Gray
2023-04-04 14:11 ` William Breathitt Gray [this message]
2023-04-04 14:12 ` [PATCH v4 3/5] iio: addac: stx104: Improve indentation in stx104_write_raw() William Breathitt Gray
2023-04-05 8:50 ` Andy Shevchenko
2023-04-05 16:11 ` William Breathitt Gray
2023-04-04 14:12 ` [PATCH v4 4/5] iio: addac: stx104: Migrate to the regmap API William Breathitt Gray
2023-04-04 14:12 ` [PATCH v4 5/5] iio: addac: stx104: Use regmap_read_poll_timeout() for conversion poll William Breathitt Gray
2023-04-05 8:54 ` Andy Shevchenko
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=2ae5e40eed5006ca735e4c12181a9ff5ced65547.1680564468.git.william.gray@linaro.org \
--to=william.gray@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®