* [PATCH] iio: accel: bma180: use iio helper function to guarantee direct mode
@ 2016-07-20 4:25 Alison Schofield
2016-07-24 11:39 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Alison Schofield @ 2016-07-20 4:25 UTC (permalink / raw)
To: jic23; +Cc: knaack.h, lars, 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>
---
Peter: I was not clear if we want to keep the data->mutex lock
in addition to claiming direct mode. I see that lock assuring
exclusivity amongst a few other tasks in the driver. Let me
know if this needs both locks. Thanks!
drivers/iio/accel/bma180.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index e3f88ba..ce5a476 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -469,13 +469,12 @@ static int bma180_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
- mutex_lock(&data->mutex);
- if (iio_buffer_enabled(indio_dev)) {
- mutex_unlock(&data->mutex);
- return -EBUSY;
- }
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret)
+ return ret;
+
ret = bma180_get_data_reg(data, chan->scan_index);
- mutex_unlock(&data->mutex);
+ iio_device_release_direct_mode(indio_dev);
if (ret < 0)
return ret;
*val = sign_extend32(ret >> chan->scan_type.shift,
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: accel: bma180: use iio helper function to guarantee direct mode
2016-07-20 4:25 [PATCH] iio: accel: bma180: use iio helper function to guarantee direct mode Alison Schofield
@ 2016-07-24 11:39 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2016-07-24 11:39 UTC (permalink / raw)
To: Alison Schofield; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel
On 20/07/16 05:25, Alison Schofield 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>
> ---
> Peter: I was not clear if we want to keep the data->mutex lock
> in addition to claiming direct mode. I see that lock assuring
> exclusivity amongst a few other tasks in the driver. Let me
> know if this needs both locks. Thanks!
>
I'd go with keeping it. Makes it change obviously correct,
rather than requiring a careful analysis of the driver..
Using that lock to protect entry into buffered mode would
probably never have worked so I think we definitely need
both locks to be taken here.
Jonathan
>
> drivers/iio/accel/bma180.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index e3f88ba..ce5a476 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -469,13 +469,12 @@ static int bma180_read_raw(struct iio_dev *indio_dev,
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - mutex_lock(&data->mutex);
> - if (iio_buffer_enabled(indio_dev)) {
> - mutex_unlock(&data->mutex);
> - return -EBUSY;
> - }
> + ret = iio_device_claim_direct_mode(indio_dev);
> + if (ret)
> + return ret;
> +
> ret = bma180_get_data_reg(data, chan->scan_index);
> - mutex_unlock(&data->mutex);
> + iio_device_release_direct_mode(indio_dev);
> if (ret < 0)
> return ret;
> *val = sign_extend32(ret >> chan->scan_type.shift,
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-24 11:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-20 4:25 [PATCH] iio: accel: bma180: use iio helper function to guarantee direct mode Alison Schofield
2016-07-24 11:39 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).