Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f302378 authored by William Breathitt Gray's avatar William Breathitt Gray Committed by Greg Kroah-Hartman
Browse files

iio: addac: stx104: Fix race condition when converting analog-to-digital



[ Upstream commit 4f9b80aefb9e2f542a49d9ec087cf5919730e1dd ]

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: 4075a283 ("iio: stx104: Add IIO support for the ADC channels")
Signed-off-by: default avatarWilliam Breathitt Gray <william.gray@linaro.org>
Link: https://lore.kernel.org/r/2ae5e40eed5006ca735e4c12181a9ff5ced65547.1680790580.git.william.gray@linaro.org


Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 7251b291
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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), &reg->achan);

@@ -127,6 +129,8 @@ static int stx104_read_raw(struct iio_dev *indio_dev,
		while (ioread8(&reg->cir_asr) & BIT(7));

		*val = ioread16(&reg->ssr_ad);

		mutex_unlock(&priv->lock);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_OFFSET:
		/* get ADC bipolar/unipolar configuration */