diff options
author | Aastha Gupta | 2017-09-27 08:31:59 +0200 |
---|---|---|
committer | Jonathan Cameron | 2017-10-09 21:51:02 +0200 |
commit | 2db82e320da766c6d8a3d9c9d1cc4c45580fd701 (patch) | |
tree | 492d1879e9ad3a859000fb4fb65c0e93e913ac19 /drivers/staging/iio | |
parent | iio: adc: ina2xx: Adhere to documented ABI, use Ohm instead of uOhm (diff) | |
download | kernel-qcow2-linux-2db82e320da766c6d8a3d9c9d1cc4c45580fd701.tar.gz kernel-qcow2-linux-2db82e320da766c6d8a3d9c9d1cc4c45580fd701.tar.xz kernel-qcow2-linux-2db82e320da766c6d8a3d9c9d1cc4c45580fd701.zip |
staging: iio: adc: ad7192: use driver private lock to protect hardware state changes
The IIO subsystem is redefining iio_dev->mlock to be used by
the IIO core only for protecting device operating mode changes.
ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.
In this driver, mlock was being used to protect hardware state
changes. Replace it with a driver private lock.
Also, as there are state changes in the ad7192_ write_raw function, a lock
is added to prevent the concurrent state changes.
Signed-off-by: Aastha Gupta <aastha.gupta4104@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r-- | drivers/staging/iio/adc/ad7192.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index 1617628c34f9..cadfb96734ed 100644 --- a/drivers/staging/iio/adc/ad7192.c +++ b/drivers/staging/iio/adc/ad7192.c @@ -162,6 +162,7 @@ struct ad7192_state { u32 scale_avail[8][2]; u8 gpocon; u8 devid; + struct mutex lock; /* protect sensor state */ struct ad_sigma_delta sd; }; @@ -461,10 +462,10 @@ static int ad7192_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: - mutex_lock(&indio_dev->mlock); + mutex_lock(&st->lock); *val = st->scale_avail[AD7192_CONF_GAIN(st->conf)][0]; *val2 = st->scale_avail[AD7192_CONF_GAIN(st->conf)][1]; - mutex_unlock(&indio_dev->mlock); + mutex_unlock(&st->lock); return IIO_VAL_INT_PLUS_NANO; case IIO_TEMP: *val = 0; @@ -508,6 +509,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: ret = -EINVAL; + mutex_lock(&st->lock); for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) if (val2 == st->scale_avail[i][1]) { ret = 0; @@ -521,6 +523,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev, ad7192_calibrate_all(st); break; } + mutex_unlock(&st->lock); break; case IIO_CHAN_INFO_SAMP_FREQ: if (!val) { @@ -630,6 +633,8 @@ static int ad7192_probe(struct spi_device *spi) st = iio_priv(indio_dev); + mutex_init(&st->lock); + st->avdd = devm_regulator_get(&spi->dev, "avdd"); if (IS_ERR(st->avdd)) return PTR_ERR(st->avdd); |