* [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers
@ 2016-05-24 19:15 Alison Schofield
2016-05-24 19:16 ` [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read Alison Schofield
` (6 more replies)
0 siblings, 7 replies; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:15 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
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(-)
--
2.1.4
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
@ 2016-05-24 19:16 ` Alison Schofield
2016-05-25 10:33 ` Daniel Baluta
2016-05-24 19:16 ` [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency Alison Schofield
` (5 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:16 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
Driver was checking for direct mode but not locking it down.
Use iio_device_claim_direct_mode() to guarantee device stays
in direct mode.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7266.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 21e19b6..01240ae 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -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')
--
2.1.4
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
2016-05-24 19:16 ` [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read Alison Schofield
@ 2016-05-24 19:16 ` Alison Schofield
2016-05-25 10:34 ` Daniel Baluta
2016-05-24 19:17 ` [PATCH 3/7] iio: adc: ad7793: " Alison Schofield
` (4 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:16 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
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.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7791.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
index cf172d58..f7edacc 100644
--- a/drivers/iio/adc/ad7791.c
+++ b/drivers/iio/adc/ad7791.c
@@ -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
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
2016-05-24 19:16 ` [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read Alison Schofield
2016-05-24 19:16 ` [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency Alison Schofield
@ 2016-05-24 19:17 ` Alison Schofield
2016-05-25 10:36 ` Daniel Baluta
2016-05-24 19:18 ` [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode Alison Schofield
` (3 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:17 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
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.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7793.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index 7b07bb6..3f41cd8 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -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;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
` (2 preceding siblings ...)
2016-05-24 19:17 ` [PATCH 3/7] iio: adc: ad7793: " Alison Schofield
@ 2016-05-24 19:18 ` Alison Schofield
2016-05-25 10:37 ` Daniel Baluta
2016-05-24 19:18 ` [PATCH 5/7] iio: adc: ad7887: " Alison Schofield
` (2 subsequent siblings)
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:18 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
Replace the code that guarantees the device stays in direct mode
with iio_device_claim_direct_mode() which does same.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7476.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index be85c2a..810c9a9 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -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
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 5/7] iio: adc: ad7887: use iio helper function to guarantee direct mode
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
` (3 preceding siblings ...)
2016-05-24 19:18 ` [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode Alison Schofield
@ 2016-05-24 19:18 ` Alison Schofield
2016-05-25 10:38 ` Daniel Baluta
2016-05-24 19:19 ` [PATCH 6/7] iio: adc: ad7923: " Alison Schofield
2016-05-24 19:20 ` [PATCH 7/7] iio: adc: ad799x: " Alison Schofield
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:18 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
Replace the code that guarantees the device stays in direct mode
with iio_device_claim_direct_mode() which does same.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7887.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 2d3c397..ee2ccc1 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -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;
--
2.1.4
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 6/7] iio: adc: ad7923: use iio helper function to guarantee direct mode
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
` (4 preceding siblings ...)
2016-05-24 19:18 ` [PATCH 5/7] iio: adc: ad7887: " Alison Schofield
@ 2016-05-24 19:19 ` Alison Schofield
2016-05-25 10:41 ` Daniel Baluta
2016-05-24 19:20 ` [PATCH 7/7] iio: adc: ad799x: " Alison Schofield
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:19 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
Replace the code that guarantees the device stays in direct mode
with iio_device_claim_direct_mode() which does same.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad7923.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 45e29cc..ff444c1 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -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
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 7/7] iio: adc: ad799x: use iio helper function to guarantee direct mode
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
` (5 preceding siblings ...)
2016-05-24 19:19 ` [PATCH 6/7] iio: adc: ad7923: " Alison Schofield
@ 2016-05-24 19:20 ` Alison Schofield
2016-05-25 10:42 ` Daniel Baluta
6 siblings, 1 reply; 25+ messages in thread
From: Alison Schofield @ 2016-05-24 19:20 UTC (permalink / raw)
To: jic23; +Cc: lars, Michael.Hennerich, knaack.h, pmeerw, linux-iio, linux-kernel
Replace the code that guarantees the device stays in direct mode
with iio_device_claim_direct_mode() which does same.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
---
drivers/iio/adc/ad799x.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index a3f5254..ec0200d 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -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;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read
2016-05-24 19:16 ` [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read Alison Schofield
@ 2016-05-25 10:33 ` Daniel Baluta
2016-05-29 17:02 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:33 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> Driver was checking for direct mode but not locking it down.
> Use iio_device_claim_direct_mode() to guarantee device stays
> in direct mode.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7266.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
> index 21e19b6..01240ae 100644
> --- a/drivers/iio/adc/ad7266.c
> +++ b/drivers/iio/adc/ad7266.c
> @@ -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')
> --
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency
2016-05-24 19:16 ` [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency Alison Schofield
@ 2016-05-25 10:34 ` Daniel Baluta
2016-05-29 17:06 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:34 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> 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.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Looks good to me. We could use an Acked-by from Lars here.
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7791.c | 15 ++++-----------
> 1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
> index cf172d58..f7edacc 100644
> --- a/drivers/iio/adc/ad7791.c
> +++ b/drivers/iio/adc/ad7791.c
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency
2016-05-24 19:17 ` [PATCH 3/7] iio: adc: ad7793: " Alison Schofield
@ 2016-05-25 10:36 ` Daniel Baluta
2016-05-29 18:33 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:36 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:17 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> 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.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7793.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
> index 7b07bb6..3f41cd8 100644
> --- a/drivers/iio/adc/ad7793.c
> +++ b/drivers/iio/adc/ad7793.c
> @@ -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;
> }
>
> --
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode
2016-05-24 19:18 ` [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode Alison Schofield
@ 2016-05-25 10:37 ` Daniel Baluta
2016-05-29 18:35 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:37 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:18 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> Replace the code that guarantees the device stays in direct mode
> with iio_device_claim_direct_mode() which does same.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7476.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
> index be85c2a..810c9a9 100644
> --- a/drivers/iio/adc/ad7476.c
> +++ b/drivers/iio/adc/ad7476.c
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 5/7] iio: adc: ad7887: use iio helper function to guarantee direct mode
2016-05-24 19:18 ` [PATCH 5/7] iio: adc: ad7887: " Alison Schofield
@ 2016-05-25 10:38 ` Daniel Baluta
2016-05-29 18:35 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:38 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:18 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> Replace the code that guarantees the device stays in direct mode
> with iio_device_claim_direct_mode() which does same.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7887.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
> index 2d3c397..ee2ccc1 100644
> --- a/drivers/iio/adc/ad7887.c
> +++ b/drivers/iio/adc/ad7887.c
> @@ -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;
> --
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 6/7] iio: adc: ad7923: use iio helper function to guarantee direct mode
2016-05-24 19:19 ` [PATCH 6/7] iio: adc: ad7923: " Alison Schofield
@ 2016-05-25 10:41 ` Daniel Baluta
2016-05-29 18:36 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:41 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:19 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> Replace the code that guarantees the device stays in direct mode
> with iio_device_claim_direct_mode() which does same.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad7923.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
> index 45e29cc..ff444c1 100644
> --- a/drivers/iio/adc/ad7923.c
> +++ b/drivers/iio/adc/ad7923.c
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 7/7] iio: adc: ad799x: use iio helper function to guarantee direct mode
2016-05-24 19:20 ` [PATCH 7/7] iio: adc: ad799x: " Alison Schofield
@ 2016-05-25 10:42 ` Daniel Baluta
2016-05-29 18:39 ` Jonathan Cameron
0 siblings, 1 reply; 25+ messages in thread
From: Daniel Baluta @ 2016-05-25 10:42 UTC (permalink / raw)
To: Alison Schofield
Cc: Jonathan Cameron, Lars-Peter Clausen, Hennerich, Michael,
Hartmut Knaack, Peter Meerwald-Stadler, linux-iio,
Linux Kernel Mailing List
On Tue, May 24, 2016 at 10:20 PM, Alison Schofield <amsfield22@gmail.com> wrote:
> Replace the code that guarantees the device stays in direct mode
> with iio_device_claim_direct_mode() which does same.
>
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> ---
> drivers/iio/adc/ad799x.c | 24 +++++++++---------------
> 1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index a3f5254..ec0200d 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -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;
> }
>
> --
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read
2016-05-25 10:33 ` Daniel Baluta
@ 2016-05-29 17:02 ` Jonathan Cameron
0 siblings, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 17:02 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:33, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> Driver was checking for direct mode but not locking it down.
>> Use iio_device_claim_direct_mode() to guarantee device stays
>> in direct mode.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Looks good.
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.
Thanks,
Jonathan
>
>> ---
>> drivers/iio/adc/ad7266.c | 7 +++----
>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
>> index 21e19b6..01240ae 100644
>> --- a/drivers/iio/adc/ad7266.c
>> +++ b/drivers/iio/adc/ad7266.c
>> @@ -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')
>> --
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency
2016-05-25 10:34 ` Daniel Baluta
@ 2016-05-29 17:06 ` Jonathan Cameron
2016-05-29 17:07 ` Jonathan Cameron
2016-05-31 13:20 ` Lars-Peter Clausen
0 siblings, 2 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 17:06 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:34, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> 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.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Looks good to me. We could use an Acked-by from Lars here.
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
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
>
>> ---
>> drivers/iio/adc/ad7791.c | 15 ++++-----------
>> 1 file changed, 4 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
>> index cf172d58..f7edacc 100644
>> --- a/drivers/iio/adc/ad7791.c
>> +++ b/drivers/iio/adc/ad7791.c
>> @@ -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 majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency
2016-05-29 17:06 ` Jonathan Cameron
@ 2016-05-29 17:07 ` Jonathan Cameron
2016-05-31 13:20 ` Lars-Peter Clausen
1 sibling, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 17:07 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 29/05/16 18:06, Jonathan Cameron wrote:
> On 25/05/16 11:34, Daniel Baluta wrote:
>> On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>>> 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.
>>>
>>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>>
>> Looks good to me. We could use an Acked-by from Lars here.
>>
>> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> 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?
>
> Thanks,
>
> Jonathan
>
>>
>>> ---
>>> drivers/iio/adc/ad7791.c | 15 ++++-----------
>>> 1 file changed, 4 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
>>> index cf172d58..f7edacc 100644
>>> --- a/drivers/iio/adc/ad7791.c
>>> +++ b/drivers/iio/adc/ad7791.c
>>> @@ -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 majordomo@vger.kernel.org
>>> 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency
2016-05-25 10:36 ` Daniel Baluta
@ 2016-05-29 18:33 ` Jonathan Cameron
2016-05-31 13:21 ` Lars-Peter Clausen
0 siblings, 1 reply; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 18:33 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:36, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:17 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> 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.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
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
>
>> ---
>> drivers/iio/adc/ad7793.c | 13 ++++---------
>> 1 file changed, 4 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
>> index 7b07bb6..3f41cd8 100644
>> --- a/drivers/iio/adc/ad7793.c
>> +++ b/drivers/iio/adc/ad7793.c
>> @@ -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;
>> }
>>
>> --
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode
2016-05-25 10:37 ` Daniel Baluta
@ 2016-05-29 18:35 ` Jonathan Cameron
0 siblings, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 18:35 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:37, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:18 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> Replace the code that guarantees the device stays in direct mode
>> with iio_device_claim_direct_mode() which does same.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Straight forward one. Applied.
Thanks,
>
>> ---
>> drivers/iio/adc/ad7476.c | 11 +++++------
>> 1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
>> index be85c2a..810c9a9 100644
>> --- a/drivers/iio/adc/ad7476.c
>> +++ b/drivers/iio/adc/ad7476.c
>> @@ -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 majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 5/7] iio: adc: ad7887: use iio helper function to guarantee direct mode
2016-05-25 10:38 ` Daniel Baluta
@ 2016-05-29 18:35 ` Jonathan Cameron
0 siblings, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 18:35 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:38, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:18 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> Replace the code that guarantees the device stays in direct mode
>> with iio_device_claim_direct_mode() which does same.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Applied - thanks.
Jonathan
>
>> ---
>> drivers/iio/adc/ad7887.c | 11 +++++------
>> 1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
>> index 2d3c397..ee2ccc1 100644
>> --- a/drivers/iio/adc/ad7887.c
>> +++ b/drivers/iio/adc/ad7887.c
>> @@ -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;
>> --
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 6/7] iio: adc: ad7923: use iio helper function to guarantee direct mode
2016-05-25 10:41 ` Daniel Baluta
@ 2016-05-29 18:36 ` Jonathan Cameron
0 siblings, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 18:36 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:41, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:19 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> Replace the code that guarantees the device stays in direct mode
>> with iio_device_claim_direct_mode() which does same.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Applied, - thanks
Jonathan
>
>
>> ---
>> drivers/iio/adc/ad7923.c | 11 +++++------
>> 1 file changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
>> index 45e29cc..ff444c1 100644
>> --- a/drivers/iio/adc/ad7923.c
>> +++ b/drivers/iio/adc/ad7923.c
>> @@ -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 majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 7/7] iio: adc: ad799x: use iio helper function to guarantee direct mode
2016-05-25 10:42 ` Daniel Baluta
@ 2016-05-29 18:39 ` Jonathan Cameron
0 siblings, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2016-05-29 18:39 UTC (permalink / raw)
To: Daniel Baluta, Alison Schofield
Cc: Lars-Peter Clausen, Hennerich, Michael, Hartmut Knaack,
Peter Meerwald-Stadler, linux-iio, Linux Kernel Mailing List
On 25/05/16 11:42, Daniel Baluta wrote:
> On Tue, May 24, 2016 at 10:20 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>> Replace the code that guarantees the device stays in direct mode
>> with iio_device_claim_direct_mode() which does same.
>>
>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Applied to the togreg branch of iio.git - initially pushed out as testing for
the autobuilders to play with it.
Thanks,
Jonathan
>
>
>> ---
>> drivers/iio/adc/ad799x.c | 24 +++++++++---------------
>> 1 file changed, 9 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
>> index a3f5254..ec0200d 100644
>> --- a/drivers/iio/adc/ad799x.c
>> +++ b/drivers/iio/adc/ad799x.c
>> @@ -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;
>> }
>>
>> --
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency
2016-05-29 17:06 ` Jonathan Cameron
2016-05-29 17:07 ` Jonathan Cameron
@ 2016-05-31 13:20 ` Lars-Peter Clausen
1 sibling, 0 replies; 25+ messages in thread
From: Lars-Peter Clausen @ 2016-05-31 13:20 UTC (permalink / raw)
To: Jonathan Cameron, Daniel Baluta, Alison Schofield
Cc: Hennerich, Michael, Hartmut Knaack, Peter Meerwald-Stadler,
linux-iio, Linux Kernel Mailing List
On 05/29/2016 07:06 PM, Jonathan Cameron wrote:
> On 25/05/16 11:34, Daniel Baluta wrote:
>> On Tue, May 24, 2016 at 10:16 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>>> 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.
>>>
>>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>>
>> Looks good to me. We could use an Acked-by from Lars here.
>>
>> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> 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.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 3/7] iio: adc: ad7793: claim direct mode when writing frequency
2016-05-29 18:33 ` Jonathan Cameron
@ 2016-05-31 13:21 ` Lars-Peter Clausen
0 siblings, 0 replies; 25+ messages in thread
From: Lars-Peter Clausen @ 2016-05-31 13:21 UTC (permalink / raw)
To: Jonathan Cameron, Daniel Baluta, Alison Schofield
Cc: Hennerich, Michael, Hartmut Knaack, Peter Meerwald-Stadler,
linux-iio, Linux Kernel Mailing List
On 05/29/2016 08:33 PM, Jonathan Cameron wrote:
> On 25/05/16 11:36, Daniel Baluta wrote:
>> On Tue, May 24, 2016 at 10:17 PM, Alison Schofield <amsfield22@gmail.com> wrote:
>>> 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.
>>>
>>> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
>>> Cc: Daniel Baluta <daniel.baluta@gmail.com>
>>
>> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
> 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.
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2016-05-31 13:21 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-24 19:15 [PATCH 0/7] iio: adc: clean up claims on direct mode in ad7* drivers Alison Schofield
2016-05-24 19:16 ` [PATCH 1/7] iio: adc: ad7266: claim direct mode during sensor read Alison Schofield
2016-05-25 10:33 ` Daniel Baluta
2016-05-29 17:02 ` Jonathan Cameron
2016-05-24 19:16 ` [PATCH 2/7] iio: adc: ad7791: claim direct mode when writing frequency Alison Schofield
2016-05-25 10:34 ` Daniel Baluta
2016-05-29 17:06 ` Jonathan Cameron
2016-05-29 17:07 ` Jonathan Cameron
2016-05-31 13:20 ` Lars-Peter Clausen
2016-05-24 19:17 ` [PATCH 3/7] iio: adc: ad7793: " Alison Schofield
2016-05-25 10:36 ` Daniel Baluta
2016-05-29 18:33 ` Jonathan Cameron
2016-05-31 13:21 ` Lars-Peter Clausen
2016-05-24 19:18 ` [PATCH 4/7] iio: adc: ad7476: use iio helper function to guarantee direct mode Alison Schofield
2016-05-25 10:37 ` Daniel Baluta
2016-05-29 18:35 ` Jonathan Cameron
2016-05-24 19:18 ` [PATCH 5/7] iio: adc: ad7887: " Alison Schofield
2016-05-25 10:38 ` Daniel Baluta
2016-05-29 18:35 ` Jonathan Cameron
2016-05-24 19:19 ` [PATCH 6/7] iio: adc: ad7923: " Alison Schofield
2016-05-25 10:41 ` Daniel Baluta
2016-05-29 18:36 ` Jonathan Cameron
2016-05-24 19:20 ` [PATCH 7/7] iio: adc: ad799x: " Alison Schofield
2016-05-25 10:42 ` Daniel Baluta
2016-05-29 18:39 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.