Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1563896 > unrolled thread

[PATCH] iio: pressure: ms5611: claim direct mode during oversampling changes

Started byAlison Schofield <amsfield22@gmail.com>
First post2017-01-20 21:30 +0100
Last post2017-01-21 13:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] iio: pressure: ms5611: claim direct mode during oversampling  changes Alison Schofield <amsfield22@gmail.com> - 2017-01-20 21:30 +0100
    Re: [PATCH] iio: pressure: ms5611: claim direct mode during  oversampling changes Jonathan Cameron <jic23@kernel.org> - 2017-01-21 13:40 +0100

#1563896 — [PATCH] iio: pressure: ms5611: claim direct mode during oversampling changes

FromAlison Schofield <amsfield22@gmail.com>
Date2017-01-20 21:30 +0100
Subject[PATCH] iio: pressure: ms5611: claim direct mode during oversampling changes
Message-ID<t1NYS-3rw-27@gated-at.bofh.it>
Driver was checking for direct mode before changing oversampling
ratios, but was not locking it.  Use the claim/release helper
functions to guarantee the device stays in direct mode while the
oversampling ratios are being updated.  Continue to use the drivers
private state lock to protect against conflicting direct mode access
of the state data.

Signed-off-by: Alison Schofield <amsfield22@gmail.com>
---
 drivers/iio/pressure/ms5611_core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index 6bd53e7..2a77a2f 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -308,6 +308,7 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
 {
 	struct ms5611_state *st = iio_priv(indio_dev);
 	const struct ms5611_osr *osr = NULL;
+	int ret;
 
 	if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO)
 		return -EINVAL;
@@ -321,12 +322,11 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
 	if (!osr)
 		return -EINVAL;
 
-	mutex_lock(&st->lock);
+	ret = iio_device_claim_direct_mode(indio_dev);
+	if (ret)
+		return ret;
 
-	if (iio_buffer_enabled(indio_dev)) {
-		mutex_unlock(&st->lock);
-		return -EBUSY;
-	}
+	mutex_lock(&st->lock);
 
 	if (chan->type == IIO_TEMP)
 		st->temp_osr = osr;
@@ -334,6 +334,8 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
 		st->pressure_osr = osr;
 
 	mutex_unlock(&st->lock);
+	iio_device_release_direct_mode(indio_dev);
+
 	return 0;
 }
 
-- 
2.1.4

[toc] | [next] | [standalone]


#1564105 — Re: [PATCH] iio: pressure: ms5611: claim direct mode during oversampling changes

FromJonathan Cameron <jic23@kernel.org>
Date2017-01-21 13:40 +0100
SubjectRe: [PATCH] iio: pressure: ms5611: claim direct mode during oversampling changes
Message-ID<t237z-401-3@gated-at.bofh.it>
In reply to#1563896
On 20/01/17 20:22, Alison Schofield wrote:
> Driver was checking for direct mode before changing oversampling
> ratios, but was not locking it.  Use the claim/release helper
> functions to guarantee the device stays in direct mode while the
> oversampling ratios are being updated.  Continue to use the drivers
> private state lock to protect against conflicting direct mode access
> of the state data.
> 
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
I think this one is straight forward enough that I'm happy to take it
without confirmation from Thomaz.  

Anyone feel free to shout if I am missing something.

Thanks,

Jonathan
> ---
>  drivers/iio/pressure/ms5611_core.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
> index 6bd53e7..2a77a2f 100644
> --- a/drivers/iio/pressure/ms5611_core.c
> +++ b/drivers/iio/pressure/ms5611_core.c
> @@ -308,6 +308,7 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
>  {
>  	struct ms5611_state *st = iio_priv(indio_dev);
>  	const struct ms5611_osr *osr = NULL;
> +	int ret;
>  
>  	if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO)
>  		return -EINVAL;
> @@ -321,12 +322,11 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
>  	if (!osr)
>  		return -EINVAL;
>  
> -	mutex_lock(&st->lock);
> +	ret = iio_device_claim_direct_mode(indio_dev);
> +	if (ret)
> +		return ret;
>  
> -	if (iio_buffer_enabled(indio_dev)) {
> -		mutex_unlock(&st->lock);
> -		return -EBUSY;
> -	}
> +	mutex_lock(&st->lock);
>  
>  	if (chan->type == IIO_TEMP)
>  		st->temp_osr = osr;
> @@ -334,6 +334,8 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
>  		st->pressure_osr = osr;
>  
>  	mutex_unlock(&st->lock);
> +	iio_device_release_direct_mode(indio_dev);
> +
>  	return 0;
>  }
>  
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web