Skip to contentSkip to conversation

iio: accel: mma8452: claim direct mode during raw reads

PATCH Applied Alison Schofield 2 participants 2 messages Oct 11, 2016 – Oct 15, 2016 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: mma8452: claim direct mode during raw reads

Driver was checking for direct mode but not locking it. Use claim/release helper functions to guarantee the device stays in direct mode during raw reads.

---
 drivers/iio/accel/mma8452.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/accel/mma8452.c +4 -2
index 6e82e02..cbbc746 100644
@@ -459,12 +459,14 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (iio_buffer_enabled(indio_dev))
-			return -EBUSY;
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
 
 		mutex_lock(&data->lock);
 		ret = mma8452_read(data, buffer);
 		mutex_unlock(&data->lock);
+		iio_device_release_direct_mode(indio_dev);
 		if (ret < 0)
 			return ret;
 
Signature · 1 line
2.1.4
maintainer Applied
#1 lore raw
Quoted 5 lines · Alison Schofield

Driver was checking for direct mode but not locking it. Use claim/release helper functions to guarantee the device stays in direct mode during raw reads.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Hohum. Amazing how often we used to get this rather obvious thing wrong ;)

Thanks,

Jonathan

Quoted 26 lines
---
 drivers/iio/accel/mma8452.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/accel/mma8452.c +4 -2
index 6e82e02..cbbc746 100644
@@ -459,12 +459,14 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (iio_buffer_enabled(indio_dev))
-			return -EBUSY;
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
 
 		mutex_lock(&data->lock);
 		ret = mma8452_read(data, buffer);
 		mutex_unlock(&data->lock);
+		iio_device_release_direct_mode(indio_dev);
 		if (ret < 0)
 			return ret;