diff mbox series

[RFC,02/27] iio: chemical: scd30: Switch to sparse friendly claim/release_direct()

Message ID 20250105172613.1204781-3-jic23@kernel.org (mailing list archive)
State New
Headers show
Series iio: improve handling of direct mode claim and release | expand

Commit Message

Jonathan Cameron Jan. 5, 2025, 5:25 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

This driver caused a false positive with __cond_lock() style solution
but is fine with the simple boolean return approach now used.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/chemical/scd30_core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

David Lechner Jan. 6, 2025, 11:22 p.m. UTC | #1
On 1/5/25 11:25 AM, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> This driver caused a false positive with __cond_lock() style solution
> but is fine with the simple boolean return approach now used.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/chemical/scd30_core.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
> index d613c54cb28d..cfbf2f5e9443 100644
> --- a/drivers/iio/chemical/scd30_core.c
> +++ b/drivers/iio/chemical/scd30_core.c
> @@ -211,18 +211,19 @@ static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
>  			break;
>  		}
>  
> -		ret = iio_device_claim_direct_mode(indio_dev);
> -		if (ret)
> +		if (!iio_device_claim_direct(indio_dev)) {
> +			ret = -EBUSY;
>  			break;
> +		}
>  
>  		ret = scd30_read(state);
>  		if (ret) {
> -			iio_device_release_direct_mode(indio_dev);
> +			iio_device_release_direct(indio_dev);
>  			break;
>  		}
>  
>  		*val = state->meas[chan->address];
> -		iio_device_release_direct_mode(indio_dev);
> +		iio_device_release_direct(indio_dev);
>  		ret = IIO_VAL_INT;
>  		break;
>  	case IIO_CHAN_INFO_SCALE:

Could do with a precursor patch to use guard(mutex) to allow returning directly
everywhere and avoid break;.
diff mbox series

Patch

diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
index d613c54cb28d..cfbf2f5e9443 100644
--- a/drivers/iio/chemical/scd30_core.c
+++ b/drivers/iio/chemical/scd30_core.c
@@ -211,18 +211,19 @@  static int scd30_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const
 			break;
 		}
 
-		ret = iio_device_claim_direct_mode(indio_dev);
-		if (ret)
+		if (!iio_device_claim_direct(indio_dev)) {
+			ret = -EBUSY;
 			break;
+		}
 
 		ret = scd30_read(state);
 		if (ret) {
-			iio_device_release_direct_mode(indio_dev);
+			iio_device_release_direct(indio_dev);
 			break;
 		}
 
 		*val = state->meas[chan->address];
-		iio_device_release_direct_mode(indio_dev);
+		iio_device_release_direct(indio_dev);
 		ret = IIO_VAL_INT;
 		break;
 	case IIO_CHAN_INFO_SCALE: