Skip to content

Commit

Permalink
iio: addac: stx104: Fix race condition when converting analog-to-digital
Browse files Browse the repository at this point in the history
commit 4f9b80a upstream.

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: 4075a28 ("iio: stx104: Add IIO support for the ADC channels")
Signed-off-by: William 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
vilhelmgray authored and gregkh committed May 11, 2023
1 parent d63f8f5 commit 1890dcb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/iio/addac/stx104.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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);

Expand All @@ -124,6 +126,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 */
Expand Down

0 comments on commit 1890dcb

Please sign in to comment.