Commit 9318a9e5 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: gyro: adis16080: replace mlock with own lock

The lock is used to protect the buffer during reads. Though the spi
routines have their own locks, it may be the case that the buffer needs to
be protected before it's stored and passed to the IIO read hooks.

indio_dev's mlock was used before.
This change replaces it with the driver's own lock.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 81ba7e85
...@@ -38,10 +38,12 @@ struct adis16080_chip_info { ...@@ -38,10 +38,12 @@ struct adis16080_chip_info {
* @us: actual spi_device to write data * @us: actual spi_device to write data
* @info: chip specific parameters * @info: chip specific parameters
* @buf: transmit or receive buffer * @buf: transmit or receive buffer
* @lock lock to protect buffer during reads
**/ **/
struct adis16080_state { struct adis16080_state {
struct spi_device *us; struct spi_device *us;
const struct adis16080_chip_info *info; const struct adis16080_chip_info *info;
struct mutex lock;
__be16 buf ____cacheline_aligned; __be16 buf ____cacheline_aligned;
}; };
...@@ -82,9 +84,9 @@ static int adis16080_read_raw(struct iio_dev *indio_dev, ...@@ -82,9 +84,9 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
mutex_lock(&indio_dev->mlock); mutex_lock(&st->lock);
ret = adis16080_read_sample(indio_dev, chan->address, val); ret = adis16080_read_sample(indio_dev, chan->address, val);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&st->lock);
return ret ? ret : IIO_VAL_INT; return ret ? ret : IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
switch (chan->type) { switch (chan->type) {
...@@ -196,6 +198,8 @@ static int adis16080_probe(struct spi_device *spi) ...@@ -196,6 +198,8 @@ static int adis16080_probe(struct spi_device *spi)
/* this is only used for removal purposes */ /* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
mutex_init(&st->lock);
/* Allocate the comms buffers */ /* Allocate the comms buffers */
st->us = spi; st->us = spi;
st->info = &adis16080_chip_info[id->driver_data]; st->info = &adis16080_chip_info[id->driver_data];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment