]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: adc: ad7606: using claim_direct_scoped for code simplification
authorJorge Harrisonn <jorge.harrisonn@usp.br>
Wed, 1 May 2024 21:57:23 +0000 (18:57 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 27 May 2024 08:48:55 +0000 (09:48 +0100)
Using iio_device_claim_direct_scoped instead of calling `iio_device
_claim_direct_modeand later callingiio_device_release_direct_mode`

This should make code cleaner and error handling easier

Co-authored-by: Lais Nuto <laisnuto@usp.br>
Signed-off-by: Lais Nuto <laisnuto@usp.br>
Signed-off-by: Jorge Harrisonn <jorge.harrisonn@usp.br>
Link: https://lore.kernel.org/r/20240501215724.26655-2-jorge.harrisonn@usp.br
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7606.c

index 1928d9ae5bcffd2a0cf9c32a63487e3c76523681..3a417595294f78582c2842253c5b838c283b4df6 100644 (file)
@@ -174,17 +174,14 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               ret = iio_device_claim_direct_mode(indio_dev);
-               if (ret)
-                       return ret;
-
-               ret = ad7606_scan_direct(indio_dev, chan->address);
-               iio_device_release_direct_mode(indio_dev);
-
-               if (ret < 0)
-                       return ret;
-               *val = (short)ret;
-               return IIO_VAL_INT;
+               iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+                       ret = ad7606_scan_direct(indio_dev, chan->address);
+                       if (ret < 0)
+                               return ret;
+                       *val = (short) ret;
+                       return IIO_VAL_INT;
+               }
+               unreachable();
        case IIO_CHAN_INFO_SCALE:
                if (st->sw_mode_en)
                        ch = chan->address;