Skip to contentSkip to conversation

iio: adc: clean up claims on direct mode in ad7* drivers

PATCH Applied Alison Schofield 4 participants 25 messages May 24, 2016 – May 31, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover iio: adc: clean up claims on direct mode in ad7* drivers

This set looks at the ad7* drivers and migrates them to use the iio helper functions iio_device_claim|release_direct_mode().

The first three (7266,7791,7793) were not already holding a lock on direct mode, so this will be a change in behavior for those drivers.

The last four (7476,7887,7923,799x) were already locking so these are migrations to the claim/release helper functions.

Worth noting: This does not clean up all mlock (ab-)uses in ad799x. This driver is still using mlock in a few other places not associated with locking down direct mode.

Alison Schofield (7):
iio: adc: ad7266: claim direct mode during sensor read
iio: adc: ad7791: claim direct mode when writing frequency
iio: adc: ad7793: claim direct mode when writing frequency
iio: adc: ad7476: use iio helper function to guarantee direct mode
iio: adc: ad7887: use iio helper function to guarantee direct mode
iio: adc: ad7923: use iio helper function to guarantee direct mode
iio: adc: ad799x: use iio helper function to guarantee direct mode

 drivers/iio/adc/ad7266.c |  7 +++----
 drivers/iio/adc/ad7476.c | 11 +++++------
 drivers/iio/adc/ad7791.c | 15 ++++-----------
 drivers/iio/adc/ad7793.c | 13 ++++---------
 drivers/iio/adc/ad7887.c | 11 +++++------
 drivers/iio/adc/ad7923.c | 11 +++++------
 drivers/iio/adc/ad799x.c | 24 +++++++++---------------
 7 files changed, 35 insertions(+), 57 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/7 iio: adc: ad7266: claim direct mode during sensor read

Driver was checking for direct mode but not locking it down. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

---
 drivers/iio/adc/ad7266.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/ad7266.c +3 -4
index 21e19b6..01240ae 100644
@@ -154,12 +154,11 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		if (iio_buffer_enabled(indio_dev))
-			return -EBUSY;
-
-		ret = ad7266_read_single(st, val, chan->address);
+		ret = iio_device_claim_direct_mode(indio_dev);
 		if (ret)
 			return ret;
+		ret = ad7266_read_single(st, val, chan->address);
+		iio_device_release_direct_mode(indio_dev);
 
 		*val = (*val >> 2) & 0xfff;
 		if (chan->scan_type.sign == 's')
Signature · 1 line
2.1.4
Acked-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read

Quoted 6 lines · Alison Schofield

Driver was checking for direct mode but not locking it down. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 25 lines
---
 drivers/iio/adc/ad7266.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/ad7266.c +3 -5
index 21e19b6..01240ae 100644
@@ -154,12 +154,11 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               if (iio_buffer_enabled(indio_dev))
-                       return -EBUSY;
-
-               ret = ad7266_read_single(st, val, chan->address);
+               ret = iio_device_claim_direct_mode(indio_dev);
                if (ret)
                        return ret;
+               ret = ad7266_read_single(st, val, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                *val = (*val >> 2) & 0xfff;
                if (chan->scan_type.sign == 's')
--
maintainer
#3 lore raw

Re: [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read

Quoted 9 lines · Daniel Baluta
Quoted 6 lines · Alison Schofield

Driver was checking for direct mode but not locking it down. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Looks good.

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

Thanks,

Jonathan

Quoted 31 lines
Quoted 16 lines
---
 drivers/iio/adc/ad7266.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/adc/ad7266.c +0 -3
index 21e19b6..01240ae 100644
@@ -154,12 +154,11 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               if (iio_buffer_enabled(indio_dev))
-                       return -EBUSY;
-

drivers/iio/adc/ad7266.c static int ad7266_read_raw(struct iio_dev *indio_dev,

Quoted 10 lines
drivers/iio/adc/ad7266.c +3 -2
-               ret = ad7266_read_single(st, val, chan->address);
+               ret = iio_device_claim_direct_mode(indio_dev);
                if (ret)
                        return ret;
+               ret = ad7266_read_single(st, val, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                *val = (*val >> 2) & 0xfff;
                if (chan->scan_type.sign == 's')
--

--
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

#4 lore raw

PATCH 2/7 iio: adc: ad7791: claim direct mode when writing frequency

In reply to Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

---
 drivers/iio/adc/ad7791.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7791.c +4 -11
index cf172d58..f7edacc 100644
@@ -272,24 +272,17 @@ static ssize_t ad7791_write_frequency(struct device *dev,
 	struct ad7791_state *st = iio_priv(indio_dev);
 	int i, ret;
 
-	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
-		mutex_unlock(&indio_dev->mlock);
-		return -EBUSY;
-	}
-	mutex_unlock(&indio_dev->mlock);
-
-	ret = -EINVAL;
-
 	for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) {
 		if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) {
 
-			mutex_lock(&indio_dev->mlock);
+			ret = iio_device_claim_direct_mode(indio_dev);
+			if (ret)
+				return ret;
 			st->filter &= ~AD7791_FILTER_RATE_MASK;
 			st->filter |= i;
 			ad_sd_write_reg(&st->sd, AD7791_REG_FILTER,
 					 sizeof(st->filter), st->filter);
-			mutex_unlock(&indio_dev->mlock);
+			iio_device_release_direct_mode(indio_dev);
 			ret = 0;
 			break;
 		}
Signature · 1 line
2.1.4
Acked-by on v1 2/7
#5 lore raw

Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency

Quoted 7 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Looks good to me. We could use an Acked-by from Lars here.

Quoted 44 lines
---
 drivers/iio/adc/ad7791.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7791.c +4 -12
index cf172d58..f7edacc 100644
@@ -272,24 +272,17 @@ static ssize_t ad7791_write_frequency(struct device *dev,
        struct ad7791_state *st = iio_priv(indio_dev);
        int i, ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               mutex_unlock(&indio_dev->mlock);
-               return -EBUSY;
-       }
-       mutex_unlock(&indio_dev->mlock);
-
-       ret = -EINVAL;
-
        for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) {
                if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) {
 
-                       mutex_lock(&indio_dev->mlock);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
                        st->filter &= ~AD7791_FILTER_RATE_MASK;
                        st->filter |= i;
                        ad_sd_write_reg(&st->sd, AD7791_REG_FILTER,
                                         sizeof(st->filter), st->filter);
-                       mutex_unlock(&indio_dev->mlock);
+                       iio_device_release_direct_mode(indio_dev);
                        ret = 0;
                        break;
                }
--

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

maintainer
#6 lore raw

Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency

Quoted 6 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 6 lines
Quoted 2 lines

Looks good to me. We could use an Acked-by from Lars here.

This one is a little more interesting. I wonder if we wouldn't be better off taking the lock for the whole function rather than dropping it for short periods.

Can apply such a change at a later date however.

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

Thanks,

Jonathan

Quoted 45 lines
Quoted 45 lines
---
 drivers/iio/adc/ad7791.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7791.c +4 -12
index cf172d58..f7edacc 100644
@@ -272,24 +272,17 @@ static ssize_t ad7791_write_frequency(struct device *dev,
        struct ad7791_state *st = iio_priv(indio_dev);
        int i, ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               mutex_unlock(&indio_dev->mlock);
-               return -EBUSY;
-       }
-       mutex_unlock(&indio_dev->mlock);
-
-       ret = -EINVAL;
-
        for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) {
                if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) {
 
-                       mutex_lock(&indio_dev->mlock);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
                        st->filter &= ~AD7791_FILTER_RATE_MASK;
                        st->filter |= i;
                        ad_sd_write_reg(&st->sd, AD7791_REG_FILTER,
                                         sizeof(st->filter), st->filter);
-                       mutex_unlock(&indio_dev->mlock);
+                       iio_device_release_direct_mode(indio_dev);
                        ret = 0;
                        break;
                }
--

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

maintainer
#7 lore raw

Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency

Quoted 13 lines · Jonathan Cameron
Quoted 6 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 6 lines
Quoted 2 lines

Looks good to me. We could use an Acked-by from Lars here.

Quoted 8 lines

This one is a little more interesting. I wonder if we wouldn't be better off taking the lock for the whole function rather than dropping it for short periods.

Can apply such a change at a later date however.

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

Actually haven't seen Daniel suggesting an Ack from Lars might be good for this one I've backed it out for now.

Lars?

Quoted 56 lines

Thanks,

Jonathan

Quoted 41 lines
Quoted 41 lines
---
 drivers/iio/adc/ad7791.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/iio/adc/ad7791.c +4 -12
index cf172d58..f7edacc 100644
@@ -272,24 +272,17 @@ static ssize_t ad7791_write_frequency(struct device *dev,
        struct ad7791_state *st = iio_priv(indio_dev);
        int i, ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               mutex_unlock(&indio_dev->mlock);
-               return -EBUSY;
-       }
-       mutex_unlock(&indio_dev->mlock);
-
-       ret = -EINVAL;
-
        for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) {
                if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) {
 
-                       mutex_lock(&indio_dev->mlock);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
                        st->filter &= ~AD7791_FILTER_RATE_MASK;
                        st->filter |= i;
                        ad_sd_write_reg(&st->sd, AD7791_REG_FILTER,
                                         sizeof(st->filter), st->filter);
-                       mutex_unlock(&indio_dev->mlock);
+                       iio_device_release_direct_mode(indio_dev);
                        ret = 0;
                        break;
                }
--

2.1.4

Quoted 4 lines
Quoted 4 lines

--
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

--
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

#8 lore raw

Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency

In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron
Quoted 9 lines · Daniel Baluta
Quoted 7 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 6 lines
Quoted 3 lines

Looks good to me. We could use an Acked-by from Lars here.

This one is a little more interesting. I wonder if we wouldn't be better off taking the lock for the whole function rather than dropping it for short periods.

It will only be locked once. sysfs_streq() will only match for a single item. But you are right the code could be refactored to make that more clearer. First run the lookup look and then apply afterwards.

#9 lore raw

PATCH 3/7 iio: adc: ad7793: claim direct mode when writing frequency

In reply to Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

---
 drivers/iio/adc/ad7793.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/adc/ad7793.c +4 -9
index 7b07bb6..3f41cd8 100644
@@ -369,13 +369,6 @@ static ssize_t ad7793_write_frequency(struct device *dev,
 	long lval;
 	int i, ret;
 
-	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
-		mutex_unlock(&indio_dev->mlock);
-		return -EBUSY;
-	}
-	mutex_unlock(&indio_dev->mlock);
-
 	ret = kstrtol(buf, 10, &lval);
 	if (ret)
 		return ret;
@@ -387,12 +380,14 @@ static ssize_t ad7793_write_frequency(struct device *dev,
 
 	for (i = 0; i < 16; i++)
 		if (lval == st->chip_info->sample_freq_avail[i]) {
-			mutex_lock(&indio_dev->mlock);
+			ret = iio_device_claim_direct_mode(indio_dev);
+			if (ret)
+				return ret;
 			st->mode &= ~AD7793_MODE_RATE(-1);
 			st->mode |= AD7793_MODE_RATE(i);
 			ad_sd_write_reg(&st->sd, AD7793_REG_MODE,
 					 sizeof(st->mode), st->mode);
-			mutex_unlock(&indio_dev->mlock);
+			iio_device_release_direct_mode(indio_dev);
 			ret = 0;
 		}
 
Signature · 1 line
2.1.4
Acked-by on v1 3/7
#10 lore raw

Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency

Quoted 7 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 40 lines
---
 drivers/iio/adc/ad7793.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/adc/ad7793.c +4 -10
index 7b07bb6..3f41cd8 100644
@@ -369,13 +369,6 @@ static ssize_t ad7793_write_frequency(struct device *dev,
        long lval;
        int i, ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               mutex_unlock(&indio_dev->mlock);
-               return -EBUSY;
-       }
-       mutex_unlock(&indio_dev->mlock);
-
        ret = kstrtol(buf, 10, &lval);
        if (ret)
                return ret;
@@ -387,12 +380,14 @@ static ssize_t ad7793_write_frequency(struct device *dev,
 
        for (i = 0; i < 16; i++)
                if (lval == st->chip_info->sample_freq_avail[i]) {
-                       mutex_lock(&indio_dev->mlock);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;
                        st->mode &= ~AD7793_MODE_RATE(-1);
                        st->mode |= AD7793_MODE_RATE(i);
                        ad_sd_write_reg(&st->sd, AD7793_REG_MODE,
                                         sizeof(st->mode), st->mode);
-                       mutex_unlock(&indio_dev->mlock);
+                       iio_device_release_direct_mode(indio_dev);
                        ret = 0;
                }
 
--
maintainer
#11 lore raw

Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency

Quoted 10 lines · Daniel Baluta
Quoted 7 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Again, this one is not quite so trivial so I'll wait for Lars to take a look even though I'm happy with it.

Thanks,

Jonathan

Quoted 46 lines
Quoted 31 lines
---
 drivers/iio/adc/ad7793.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/adc/ad7793.c +3 -8
index 7b07bb6..3f41cd8 100644
@@ -369,13 +369,6 @@ static ssize_t ad7793_write_frequency(struct device *dev,
        long lval;
        int i, ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               mutex_unlock(&indio_dev->mlock);
-               return -EBUSY;
-       }
-       mutex_unlock(&indio_dev->mlock);
-
        ret = kstrtol(buf, 10, &lval);
        if (ret)
                return ret;
@@ -387,12 +380,14 @@ static ssize_t ad7793_write_frequency(struct device *dev,
 
        for (i = 0; i < 16; i++)
                if (lval == st->chip_info->sample_freq_avail[i]) {
-                       mutex_lock(&indio_dev->mlock);
+                       ret = iio_device_claim_direct_mode(indio_dev);
+                       if (ret)
+                               return ret;

drivers/iio/adc/ad7793.c static ssize_t ad7793_write_frequency(struct device *dev,

Quoted 10 lines
drivers/iio/adc/ad7793.c +1 -2
                        st->mode &= ~AD7793_MODE_RATE(-1);
                        st->mode |= AD7793_MODE_RATE(i);
                        ad_sd_write_reg(&st->sd, AD7793_REG_MODE,
                                         sizeof(st->mode), st->mode);
-                       mutex_unlock(&indio_dev->mlock);
+                       iio_device_release_direct_mode(indio_dev);
                        ret = 0;
                }
 
--

--
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

#12 lore raw

Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency

Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

Driver was checking for direct mode and trying to lock it, but left a gap where mode could change before the desired operation. Use iio_device_claim_direct_mode() to guarantee device stays in direct mode.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Again, this one is not quite so trivial so I'll wait for Lars to take a look even though I'm happy with it.

Same as patch too. Looks good otherwise.

#13 lore raw

PATCH 4/7 iio: adc: ad7476: use iio helper function to guarantee direct mode

In reply to Alison Schofield

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

---
 drivers/iio/adc/ad7476.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7476.c +5 -6
index be85c2a..810c9a9 100644
@@ -106,12 +106,11 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
-		if (iio_buffer_enabled(indio_dev))
-			ret = -EBUSY;
-		else
-			ret = ad7476_scan_direct(st);
-		mutex_unlock(&indio_dev->mlock);
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+		ret = ad7476_scan_direct(st);
+		iio_device_release_direct_mode(indio_dev);
 
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.1.4
Acked-by on v1 4/7
#14 lore raw

Re: [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode

Quoted 5 lines · Alison Schofield

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

Quoted 33 lines
---
 drivers/iio/adc/ad7476.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7476.c +5 -7
index be85c2a..810c9a9 100644
@@ -106,12 +106,11 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7476_scan_direct(st);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7476_scan_direct(st);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--

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

maintainer
#15 lore raw

Re: [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode

Quoted 8 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

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

Straight forward one. Applied.

Thanks,

Quoted 34 lines
Quoted 34 lines
---
 drivers/iio/adc/ad7476.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7476.c +5 -7
index be85c2a..810c9a9 100644
@@ -106,12 +106,11 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7476_scan_direct(st);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7476_scan_direct(st);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--

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

#16 lore raw

PATCH 5/7 iio: adc: ad7887: use iio helper function to guarantee direct mode

In reply to Alison Schofield

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

---
 drivers/iio/adc/ad7887.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7887.c +5 -6
index 2d3c397..ee2ccc1 100644
@@ -156,12 +156,11 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
-		if (iio_buffer_enabled(indio_dev))
-			ret = -EBUSY;
-		else
-			ret = ad7887_scan_direct(st, chan->address);
-		mutex_unlock(&indio_dev->mlock);
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+		ret = ad7887_scan_direct(st, chan->address);
+		iio_device_release_direct_mode(indio_dev);
 
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.1.4
Acked-by on v1 5/7
#17 lore raw

Re: [PATCH 5/7] iio: adc: ad7887: use iio helper function to guarantee direct mode

Quoted 5 lines · Alison Schofield

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

Quoted 27 lines
---
 drivers/iio/adc/ad7887.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7887.c +5 -7
index 2d3c397..ee2ccc1 100644
@@ -156,12 +156,11 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7887_scan_direct(st, chan->address);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7887_scan_direct(st, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--
maintainer
#18 lore raw

Re: [PATCH 5/7] iio: adc: ad7887: use iio helper function to guarantee direct mode

Quoted 8 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

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

Applied - thanks.

Jonathan

Quoted 33 lines
Quoted 18 lines
---
 drivers/iio/adc/ad7887.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7887.c +0 -5
index 2d3c397..ee2ccc1 100644
@@ -156,12 +156,11 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7887_scan_direct(st, chan->address);

drivers/iio/adc/ad7887.c static int ad7887_read_raw(struct iio_dev *indio_dev,

Quoted 10 lines
drivers/iio/adc/ad7887.c +5 -2
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7887_scan_direct(st, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--

--
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

#19 lore raw

PATCH 6/7 iio: adc: ad7923: use iio helper function to guarantee direct mode

In reply to Alison Schofield

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

---
 drivers/iio/adc/ad7923.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7923.c +5 -6
index 45e29cc..ff444c1 100644
@@ -233,12 +233,11 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
-		if (iio_buffer_enabled(indio_dev))
-			ret = -EBUSY;
-		else
-			ret = ad7923_scan_direct(st, chan->address);
-		mutex_unlock(&indio_dev->mlock);
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+		ret = ad7923_scan_direct(st, chan->address);
+		iio_device_release_direct_mode(indio_dev);
 
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.1.4
Acked-by on v1 6/7
#20 lore raw

Re: [PATCH 6/7] iio: adc: ad7923: use iio helper function to guarantee direct mode

Quoted 5 lines · Alison Schofield

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

Quoted 33 lines
---
 drivers/iio/adc/ad7923.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7923.c +5 -7
index 45e29cc..ff444c1 100644
@@ -233,12 +233,11 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7923_scan_direct(st, chan->address);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7923_scan_direct(st, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--

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

maintainer Applied
#21 lore raw

Re: [PATCH 6/7] iio: adc: ad7923: use iio helper function to guarantee direct mode

Quoted 8 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

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

Applied, - thanks

Jonathan

Quoted 35 lines
Quoted 35 lines

---
 drivers/iio/adc/ad7923.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iio/adc/ad7923.c +5 -7
index 45e29cc..ff444c1 100644
@@ -233,12 +233,11 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad7923_scan_direct(st, chan->address);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad7923_scan_direct(st, chan->address);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
--

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

#22 lore raw

PATCH 7/7 iio: adc: ad799x: use iio helper function to guarantee direct mode

In reply to Alison Schofield

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

---
 drivers/iio/adc/ad799x.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/iio/adc/ad799x.c +9 -15
index a3f5254..ec0200d 100644
@@ -282,12 +282,11 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
 
 	switch (m) {
 	case IIO_CHAN_INFO_RAW:
-		mutex_lock(&indio_dev->mlock);
-		if (iio_buffer_enabled(indio_dev))
-			ret = -EBUSY;
-		else
-			ret = ad799x_scan_direct(st, chan->scan_index);
-		mutex_unlock(&indio_dev->mlock);
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+		ret = ad799x_scan_direct(st, chan->scan_index);
+		iio_device_release_direct_mode(indio_dev);
 
 		if (ret < 0)
 			return ret;
@@ -395,11 +394,9 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
 	struct ad799x_state *st = iio_priv(indio_dev);
 	int ret;
 
-	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
-		ret = -EBUSY;
-		goto done;
-	}
+	ret = iio_device_claim_direct_mode(indio_dev);
+	if (ret)
+		return ret;
 
 	if (state)
 		st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
@@ -412,10 +409,7 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
 		st->config &= ~AD7998_ALERT_EN;
 
 	ret = ad799x_write_config(st, st->config);
-
-done:
-	mutex_unlock(&indio_dev->mlock);
-
+	iio_device_release_direct_mode(indio_dev);
 	return ret;
 }
 
Signature · 1 line
2.1.4
Acked-by on v1 7/7
#23 lore raw

Re: [PATCH 7/7] iio: adc: ad799x: use iio helper function to guarantee direct mode

Quoted 5 lines · Alison Schofield

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

Quoted 54 lines
---
 drivers/iio/adc/ad799x.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/iio/adc/ad799x.c +9 -16
index a3f5254..ec0200d 100644
@@ -282,12 +282,11 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad799x_scan_direct(st, chan->scan_index);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad799x_scan_direct(st, chan->scan_index);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
@@ -395,11 +394,9 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
        struct ad799x_state *st = iio_priv(indio_dev);
        int ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               ret = -EBUSY;
-               goto done;
-       }
+       ret = iio_device_claim_direct_mode(indio_dev);
+       if (ret)
+               return ret;
 
        if (state)
                st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
@@ -412,10 +409,7 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
                st->config &= ~AD7998_ALERT_EN;
 
        ret = ad799x_write_config(st, st->config);
-
-done:
-       mutex_unlock(&indio_dev->mlock);
-
+       iio_device_release_direct_mode(indio_dev);
        return ret;
 }
 
--
maintainer
#24 lore raw

Re: [PATCH 7/7] iio: adc: ad799x: use iio helper function to guarantee direct mode

Quoted 8 lines · Daniel Baluta
Quoted 5 lines · Alison Schofield

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

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

Thanks,

Jonathan

Quoted 61 lines
Quoted 46 lines

---
 drivers/iio/adc/ad799x.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/iio/adc/ad799x.c +8 -11
index a3f5254..ec0200d 100644
@@ -282,12 +282,11 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&indio_dev->mlock);
-               if (iio_buffer_enabled(indio_dev))
-                       ret = -EBUSY;
-               else
-                       ret = ad799x_scan_direct(st, chan->scan_index);
-               mutex_unlock(&indio_dev->mlock);
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret)
+                       return ret;
+               ret = ad799x_scan_direct(st, chan->scan_index);
+               iio_device_release_direct_mode(indio_dev);
 
                if (ret < 0)
                        return ret;
@@ -395,11 +394,9 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
        struct ad799x_state *st = iio_priv(indio_dev);
        int ret;
 
-       mutex_lock(&indio_dev->mlock);
-       if (iio_buffer_enabled(indio_dev)) {
-               ret = -EBUSY;
-               goto done;
-       }
+       ret = iio_device_claim_direct_mode(indio_dev);
+       if (ret)
+               return ret;
 
        if (state)
                st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
@@ -412,10 +409,7 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
                st->config &= ~AD7998_ALERT_EN;
 

drivers/iio/adc/ad799x.c static int ad799x_write_event_config(struct iio_dev *indio_dev,

Quoted 10 lines
drivers/iio/adc/ad799x.c +1 -5
        ret = ad799x_write_config(st, st->config);
-
-done:
-       mutex_unlock(&indio_dev->mlock);
-
+       iio_device_release_direct_mode(indio_dev);
        return ret;
 }
 
--

--
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