Skip to contentSkip to conversation

iio: proximity: sx9500: claim direct mode during raw proximity reads

PATCH In review Alison Schofield 3 participants 3 messages Jan 20, 2017 – Jan 21, 2017 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: proximity: sx9500: claim direct mode during raw proximity reads

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

---
 drivers/iio/proximity/sx9500.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/proximity/sx9500.c +7 -3
index 1f06282..9ea147f 100644
@@ -387,14 +387,18 @@ static int sx9500_read_raw(struct iio_dev *indio_dev,
 			   int *val, int *val2, long mask)
 {
 	struct sx9500_data *data = iio_priv(indio_dev);
+	int ret;
 
 	switch (chan->type) {
 	case IIO_PROXIMITY:
 		switch (mask) {
 		case IIO_CHAN_INFO_RAW:
-			if (iio_buffer_enabled(indio_dev))
-				return -EBUSY;
-			return sx9500_read_proximity(data, chan, val);
+			ret = iio_device_claim_direct_mode(indio_dev);
+			if (ret)
+				return ret;
+			ret = sx9500_read_proximity(data, chan, val);
+			iio_device_release_direct_mode(indio_dev);
+			return ret;
 		case IIO_CHAN_INFO_SAMP_FREQ:
 			return sx9500_read_samp_freq(data, val, val2);
 		default:
Signature · 1 line
2.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Alison Schofield

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

Quoted 33 lines
---
 drivers/iio/proximity/sx9500.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/proximity/sx9500.c +7 -4
index 1f06282..9ea147f 100644
@@ -387,14 +387,18 @@ static int sx9500_read_raw(struct iio_dev *indio_dev,
                           int *val, int *val2, long mask)
 {
        struct sx9500_data *data = iio_priv(indio_dev);
+       int ret;
 
        switch (chan->type) {
        case IIO_PROXIMITY:
                switch (mask) {
                case IIO_CHAN_INFO_RAW:
-                       if (iio_buffer_enabled(indio_dev))
-                               return -EBUSY;
-                       return sx9500_read_proximity(data, chan, val);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
+                       ret = sx9500_read_proximity(data, chan, val);
+                       iio_device_release_direct_mode(indio_dev);
+                       return ret;
                case IIO_CHAN_INFO_SAMP_FREQ:
                        return sx9500_read_samp_freq(data, val, val2);
                default:
--

2.1.4

maintainer
#2 lore raw
Quoted 8 lines · Vlad Dogaru
Quoted 5 lines · Alison Schofield

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

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

Thanks,

Jonathan

Quoted 39 lines
Quoted 32 lines
---
 drivers/iio/proximity/sx9500.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/proximity/sx9500.c +7 -4
index 1f06282..9ea147f 100644
@@ -387,14 +387,18 @@ static int sx9500_read_raw(struct iio_dev *indio_dev,
                           int *val, int *val2, long mask)
 {
        struct sx9500_data *data = iio_priv(indio_dev);
+       int ret;
 
        switch (chan->type) {
        case IIO_PROXIMITY:
                switch (mask) {
                case IIO_CHAN_INFO_RAW:
-                       if (iio_buffer_enabled(indio_dev))
-                               return -EBUSY;
-                       return sx9500_read_proximity(data, chan, val);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
+                       ret = sx9500_read_proximity(data, chan, val);
+                       iio_device_release_direct_mode(indio_dev);
+                       return ret;
                case IIO_CHAN_INFO_SAMP_FREQ:
                        return sx9500_read_samp_freq(data, val, val2);
                default:
--
Quoted 2 lines

2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html