]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: adc: ad7124: use guard(mutex) to simplify return paths
authorDavid Lechner <dlechner@baylibre.com>
Thu, 11 Sep 2025 21:42:02 +0000 (16:42 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 13 Sep 2025 13:38:42 +0000 (14:38 +0100)
Use guard(mutex) in a couple of functions to allow direct returns. This
simplifies the code a bit and will make later changes easier.

cleanup.h was already included for prior use of __free()

Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7124.c

index 58f072c6bc67889a60fdb3cd53186c03caac7c76..789cfacd2eb01be79bac617a1b922273b2c1a746 100644 (file)
@@ -739,24 +739,20 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
 {
        struct ad7124_state *st = iio_priv(indio_dev);
        unsigned int res, gain, full_scale, vref;
-       int ret = 0;
 
-       mutex_lock(&st->cfgs_lock);
+       guard(mutex)(&st->cfgs_lock);
 
        switch (info) {
        case IIO_CHAN_INFO_SAMP_FREQ:
-               if (val2 != 0 || val == 0) {
-                       ret = -EINVAL;
-                       break;
-               }
+               if (val2 != 0 || val == 0)
+                       return -EINVAL;
 
                ad7124_set_channel_odr(st, chan->address, val);
-               break;
+
+               return 0;
        case IIO_CHAN_INFO_SCALE:
-               if (val != 0) {
-                       ret = -EINVAL;
-                       break;
-               }
+               if (val != 0)
+                       return -EINVAL;
 
                if (st->channels[chan->address].cfg.bipolar)
                        full_scale = 1 << (chan->scan_type.realbits - 1);
@@ -772,13 +768,10 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
                        st->channels[chan->address].cfg.live = false;
 
                st->channels[chan->address].cfg.pga_bits = res;
-               break;
+               return 0;
        default:
-               ret = -EINVAL;
+               return -EINVAL;
        }
-
-       mutex_unlock(&st->cfgs_lock);
-       return ret;
 }
 
 static int ad7124_reg_access(struct iio_dev *indio_dev,
@@ -810,7 +803,8 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
        int ret;
        int i;
 
-       mutex_lock(&st->cfgs_lock);
+       guard(mutex)(&st->cfgs_lock);
+
        for (i = 0; i < st->num_channels; i++) {
                bit_set = test_bit(i, scan_mask);
                if (bit_set)
@@ -818,15 +812,10 @@ static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
                else
                        ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i), AD7124_CHANNEL_ENABLE,
                                                    0, 2);
-               if (ret < 0) {
-                       mutex_unlock(&st->cfgs_lock);
-
+               if (ret < 0)
                        return ret;
-               }
        }
 
-       mutex_unlock(&st->cfgs_lock);
-
        return 0;
 }