public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: kernel-lts@openela.org
Cc: William Breathitt Gray <william.gray@linaro.org>,
	Stable@vger.kernel.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.14-openela 008/190] iio: addac: stx104: Fix race condition for stx104_write_raw()
Date: Mon, 15 Apr 2024 06:48:58 -0400	[thread overview]
Message-ID: <20240415105208.3137874-9-sashal@kernel.org> (raw)
In-Reply-To: <20240415105208.3137874-1-sashal@kernel.org>

From: William Breathitt Gray <william.gray@linaro.org>

[ Upstream commit 9740827468cea80c42db29e7171a50e99acf7328 ]

The priv->chan_out_states array and actual DAC value can become
mismatched if stx104_write_raw() is called concurrently. Prevent such a
race condition by utilizing a mutex.

Fixes: 97a445dad37a ("iio: Add IIO support for the DAC on the Apex Embedded Systems STX104")
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
Link: https://lore.kernel.org/r/c95c9a77fcef36b2a052282146950f23bbc1ebdc.1680790580.git.william.gray@linaro.org
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/iio/adc/stx104.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/adc/stx104.c b/drivers/iio/adc/stx104.c
index 2da741d27540f..edc3b29eed621 100644
--- a/drivers/iio/adc/stx104.c
+++ b/drivers/iio/adc/stx104.c
@@ -23,6 +23,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
 #include <linux/spinlock.h>
 
 #define STX104_OUT_CHAN(chan) {				\
@@ -54,10 +55,12 @@ MODULE_PARM_DESC(base, "Apex Embedded Systems STX104 base addresses");
 
 /**
  * struct stx104_iio - IIO device private data structure
+ * @lock: synchronization lock to prevent I/O race conditions
  * @chan_out_states:	channels' output states
  * @base:		base port address of the IIO device
  */
 struct stx104_iio {
+	struct mutex lock;
 	unsigned int chan_out_states[STX104_NUM_OUT_CHAN];
 	unsigned int base;
 };
@@ -160,9 +163,12 @@ static int stx104_write_raw(struct iio_dev *indio_dev,
 			if ((unsigned int)val > 65535)
 				return -EINVAL;
 
+			mutex_lock(&priv->lock);
+
 			priv->chan_out_states[chan->channel] = val;
 			outw(val, priv->base + 4 + 2 * chan->channel);
 
+			mutex_unlock(&priv->lock);
 			return 0;
 		}
 		return -EINVAL;
@@ -323,6 +329,8 @@ static int stx104_probe(struct device *dev, unsigned int id)
 	priv = iio_priv(indio_dev);
 	priv->base = base[id];
 
+	mutex_init(&priv->lock);
+
 	/* configure device for software trigger operation */
 	outb(0, base[id] + 9);
 
-- 
2.43.0


  parent reply	other threads:[~2024-04-15 13:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240415105208.3137874-1-sashal@kernel.org>
2024-04-15 10:48 ` [PATCH 4.14-openela 003/190] ALSA: jack: Fix mutex call in snd_jack_report() Sasha Levin
2024-04-15 10:48 ` [PATCH 4.14-openela 004/190] pinctrl: amd: Detect internal GPIO0 debounce handling Sasha Levin
2024-04-15 10:48 ` [PATCH 4.14-openela 005/190] btrfs: fix extent buffer leak after tree mod log failure at split_node() Sasha Levin
2024-04-15 10:48 ` [PATCH 4.14-openela 007/190] IMA: allow/fix UML builds Sasha Levin
2024-04-15 10:48 ` Sasha Levin [this message]
2024-04-15 10:48 ` [PATCH 4.14-openela 009/190] block: fix signed int overflow in Amiga partition support Sasha Levin
2024-04-15 13:58   ` Geert Uytterhoeven
2024-04-15 10:49 ` [PATCH 4.14-openela 012/190] selftests/ftrace: Add new test case which checks non unique symbol Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 013/190] iio: exynos-adc: request second interupt only when touchscreen mode is used Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 021/190] MIPS: KVM: Fix a build warning about variable set but not used Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 022/190] smb3: fix touch -h of symlink Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 023/190] fbdev: stifb: Make the STI next font pointer a 32-bit signed offset Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 025/190] arm64: dts: mediatek: mt8173-evb: Fix regulator-fixed node names Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 028/190] btrfs: do not allow non subvolume root targets for snapshot Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 029/190] smb: client: fix OOB in smbCalcSize() Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 031/190] IB/hfi1: Fix sdma.h tx->num_descs off-by-one error Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 032/190] pinctrl: amd: Only use special debounce behavior for GPIO 0 Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 033/190] PCI: qcom: Disable write access to read only registers for IP v2.3.3 Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 034/190] ASoC: cs42l51: fix driver to properly autoload with automatic module loading Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 044/190] PCI: keystone: Don't discard .remove() callback Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 045/190] PCI: keystone: Don't discard .probe() callback Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 046/190] ksmbd: fix wrong name of SMB2_CREATE_ALLOCATION_SIZE Sasha Levin
2024-04-15 10:49 ` [PATCH 4.14-openela 049/190] usb: musb: fix MUSB_QUIRK_B_DISCONNECT_99 handling Sasha Levin

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=20240415105208.3137874-9-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Stable@vger.kernel.org \
    --cc=kernel-lts@openela.org \
    --cc=william.gray@linaro.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