FAILED: patch "[PATCH] iio: addac: stx104: Fix race condition for stx104_write_raw()" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 9740827468cea80c42db29e7171a50e99acf7328
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023050617-catwalk-filled-0df3@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9740827468cea80c42db29e7171a50e99acf7328 Mon Sep 17 00:00:00 2001
From: William Breathitt Gray <[email protected]>
Date: Thu, 6 Apr 2023 10:40:10 -0400
Subject: [PATCH] iio: addac: stx104: Fix race condition for stx104_write_raw()
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.
drivers/iio/addac/stx104.c +8 -0
@@ -15,6 +15,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> +#include <linux/mutex.h> #include <linux/spinlock.h> #include <linux/types.h>
@@ -69,10 +70,12 @@ struct stx104_reg {/** * struct stx104_iio - IIO device private data structure +* @lock: synchronization lock to prevent I/O race conditions * @chan_out_states: channels' output states * @reg: I/O address offset for the device registers */ struct stx104_iio { +struct mutex lock;unsigned int chan_out_states[STX104_NUM_OUT_CHAN ];struct stx104_reg __iomem *reg; };
@@ -178,9 +181,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;iowrite16 (val, &priv->reg->dac[chan->channel]); +mutex_unlock (&priv->lock);return 0 ; }return -EINVAL ;
@@ -351,6 +357,8 @@ static int stx104_probe(struct device *dev, unsigned int id) indio_dev->name =dev_name (dev); +mutex_init (&priv->lock); +/* configure device for software trigger operation */ iowrite8 (0 , &priv->reg->acr);