iio: adc: ti-adc161s626: make use of iio_device_claim_direct_scoped()
authorGustavo Ueti Fukunaga <gustavofukunaga@usp.br>
Mon, 27 May 2024 09:19:40 +0000 (06:19 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 13 Jun 2024 18:19:22 +0000 (19:19 +0100)
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>
Link: https://lore.kernel.org/r/20240527091942.53616-1-gustavofukunaga@usp.br
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ti-adc161s626.c

index b789891..f7c78d0 100644 (file)
@@ -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)