diff mbox series

iio: adc: ti-adc161s626: make use of iio_device_claim_direct_scoped()

Message ID 20240527091942.53616-1-gustavofukunaga@usp.br (mailing list archive)
State Accepted
Headers show
Series iio: adc: ti-adc161s626: make use of iio_device_claim_direct_scoped() | expand

Commit Message

Gustavo Ueti Fukunaga May 27, 2024, 9:19 a.m. UTC
Make use of iio_device_claim_direct_scoped() to make error handling more
natural and simplify code.

Co-developed-by: Caio Dantas Simão Ugêda <caiodantas@usp.br>
Signed-off-by: Caio Dantas Simão Ugêda <caiodantas@usp.br>
Signed-off-by: Gustavo Ueti Fukunaga <gustavofukunaga@usp.br>
---
 drivers/iio/adc/ti-adc161s626.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Jonathan Cameron June 2, 2024, 1:09 p.m. UTC | #1
On Mon, 27 May 2024 06:19:40 -0300
Gustavo Ueti Fukunaga <gustavofukunaga@usp.br> wrote:

> Make use of iio_device_claim_direct_scoped() to make error handling more
> natural and simplify code.
> 
> Co-developed-by: Caio Dantas Simão Ugêda <caiodantas@usp.br>
> Signed-off-by: Caio Dantas Simão Ugêda <caiodantas@usp.br>
> Signed-off-by: Gustavo Ueti Fukunaga <gustavofukunaga@usp.br>
Applied to the togreg branch of iio.git and initially pushed out as testing
for 0-day to poke at it and see what we missed.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ti-adc161s626.c | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-adc161s626.c b/drivers/iio/adc/ti-adc161s626.c
> index b789891dc..f7c78d0dd 100644
> --- a/drivers/iio/adc/ti-adc161s626.c
> +++ b/drivers/iio/adc/ti-adc161s626.c
> @@ -137,17 +137,13 @@ static int ti_adc_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		ret = iio_device_claim_direct_mode(indio_dev);
> -		if (ret)
> -			return ret;
> -
> -		ret = ti_adc_read_measurement(data, chan, val);
> -		iio_device_release_direct_mode(indio_dev);
> -
> -		if (ret)
> -			return ret;
> -
> -		return IIO_VAL_INT;
> +		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> +			ret = ti_adc_read_measurement(data, chan, val);
> +			if (ret)
> +				return ret;
> +			return IIO_VAL_INT;
> +		}
> +		unreachable();
>  	case IIO_CHAN_INFO_SCALE:
>  		ret = regulator_get_voltage(data->ref);
>  		if (ret < 0)
diff mbox series

Patch

diff --git a/drivers/iio/adc/ti-adc161s626.c b/drivers/iio/adc/ti-adc161s626.c
index b789891dc..f7c78d0dd 100644
--- a/drivers/iio/adc/ti-adc161s626.c
+++ b/drivers/iio/adc/ti-adc161s626.c
@@ -137,17 +137,13 @@  static int ti_adc_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		ret = iio_device_claim_direct_mode(indio_dev);
-		if (ret)
-			return ret;
-
-		ret = ti_adc_read_measurement(data, chan, val);
-		iio_device_release_direct_mode(indio_dev);
-
-		if (ret)
-			return ret;
-
-		return IIO_VAL_INT;
+		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+			ret = ti_adc_read_measurement(data, chan, val);
+			if (ret)
+				return ret;
+			return IIO_VAL_INT;
+		}
+		unreachable();
 	case IIO_CHAN_INFO_SCALE:
 		ret = regulator_get_voltage(data->ref);
 		if (ret < 0)