iio: accel: mma8452: claim direct mode during raw reads
authorAlison Schofield <amsfield22@gmail.com>
Tue, 11 Oct 2016 19:31:36 +0000 (12:31 -0700)
committerJonathan Cameron <jic23@kernel.org>
Sun, 23 Oct 2016 18:33:54 +0000 (19:33 +0100)
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.

Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/mma8452.c

index 1c7051581513f455b4702826325c35208c6efa10..7951def89d63856d1aaccc5d35d668f0e5175eca 100644 (file)
@@ -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;