Skip to contentSkip to conversation

iio: accel: bma180: use iio helper function to guarantee direct mode

PATCH Superseded Alison Schofield 2 participants 2 messages Jul 20, 2016 – Jul 24, 2016 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: bma180: use iio helper function to guarantee direct mode

Replace the code that guarantees the device stays in direct mode with iio_device_claim_direct_mode() which does same.

---
Peter: I was not clear if we want to keep the data->mutex lock in addition to claiming direct mode. I see that lock assuring exclusivity amongst a few other tasks in the driver. Let me know if this needs both locks. Thanks!

 drivers/iio/accel/bma180.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/accel/bma180.c +5 -6
index e3f88ba..ce5a476 100644
@@ -469,13 +469,12 @@ static int bma180_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&data->mutex);
-		if (iio_buffer_enabled(indio_dev)) {
-			mutex_unlock(&data->mutex);
-			return -EBUSY;
-		}
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+
 		ret = bma180_get_data_reg(data, chan->scan_index);
-		mutex_unlock(&data->mutex);
+		iio_device_release_direct_mode(indio_dev);
 		if (ret < 0)
 			return ret;
 		*val = sign_extend32(ret >> chan->scan_type.shift,
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 11 lines · Alison Schofield

Replace the code that guarantees the device stays in direct mode with iio_device_claim_direct_mode() which does same.

---
Peter: I was not clear if we want to keep the data->mutex lock in addition to claiming direct mode. I see that lock assuring exclusivity amongst a few other tasks in the driver. Let me know if this needs both locks. Thanks!

I'd go with keeping it. Makes it change obviously correct, rather than requiring a careful analysis of the driver..

Using that lock to protect entry into buffered mode would probably never have worked so I think we definitely need both locks to be taken here.

Jonathan

Quoted 28 lines
 drivers/iio/accel/bma180.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/accel/bma180.c +5 -6
index e3f88ba..ce5a476 100644
@@ -469,13 +469,12 @@ static int bma180_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&data->mutex);
-		if (iio_buffer_enabled(indio_dev)) {
-			mutex_unlock(&data->mutex);
-			return -EBUSY;
-		}
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+
 		ret = bma180_get_data_reg(data, chan->scan_index);
-		mutex_unlock(&data->mutex);
+		iio_device_release_direct_mode(indio_dev);
 		if (ret < 0)
 			return ret;
 		*val = sign_extend32(ret >> chan->scan_type.shift,