summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNuno Sá <nuno.sa@analog.com>2022-09-20 13:28:07 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-12-31 13:33:10 +0100
commit49cfd1f61f445e34dc7dbe98ac2c261e07c6bf19 (patch)
treef164651bbcf087b39483fd53f927aa554bcb7271
parenta154b1c139fbf6a49762159be81d425d41ceec87 (diff)
downloadlinux-stable-49cfd1f61f445e34dc7dbe98ac2c261e07c6bf19.tar.gz
linux-stable-49cfd1f61f445e34dc7dbe98ac2c261e07c6bf19.tar.bz2
linux-stable-49cfd1f61f445e34dc7dbe98ac2c261e07c6bf19.zip
iio: adc: ad_sigma_delta: do not use internal iio_dev lock
commit 20228a1d5a55e7db0c6720840f2c7d2b48c55f69 upstream. Drop 'mlock' usage by making use of iio_device_claim_direct_mode(). This change actually makes sure we cannot do a single conversion while buffering is enable. Note there was a potential race in the previous code since we were only acquiring the lock after checking if the bus is enabled. Fixes: af3008485ea0 ("iio:adc: Add common code for ADI Sigma Delta devices") Signed-off-by: Nuno Sá <nuno.sa@analog.com> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Cc: <Stable@vger.kernel.org> #No rush as race is very old. Link: https://lore.kernel.org/r/20220920112821.975359-2-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/iio/adc/ad_sigma_delta.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 261a9a6b45e1..d8570f620785 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -281,10 +281,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
unsigned int data_reg;
int ret = 0;
- if (iio_buffer_enabled(indio_dev))
- return -EBUSY;
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret)
+ return ret;
- mutex_lock(&indio_dev->mlock);
ad_sigma_delta_set_channel(sigma_delta, chan->address);
spi_bus_lock(sigma_delta->spi->master);
@@ -323,7 +323,7 @@ out:
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
sigma_delta->bus_locked = false;
spi_bus_unlock(sigma_delta->spi->master);
- mutex_unlock(&indio_dev->mlock);
+ iio_device_release_direct_mode(indio_dev);
if (ret)
return ret;