]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: dac: ltc2688: use the auto lock API
authorNuno Sá <nuno.sa@analog.com>
Mon, 29 Sep 2025 13:35:32 +0000 (14:35 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Oct 2025 10:59:18 +0000 (11:59 +0100)
Make use of the cleanup API so that we can simplify some code paths.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/dac/ltc2688.c

index 57028d422868ec48e6900ef1cc4be6dee9cd4547..02f408229681b97fdd85ca04d08b355935f36280 100644 (file)
@@ -6,6 +6,7 @@
  */
 #include <linux/bitfield.h>
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/gpio/consumer.h>
@@ -208,12 +209,12 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
                code = FIELD_PREP(LTC2688_DITHER_RAW_MASK, code);
        }
 
-       mutex_lock(&st->lock);
+       guard(mutex)(&st->lock);
        /* select the correct input register to read from */
        ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
                                 input << chan);
        if (ret)
-               goto out_unlock;
+               return ret;
 
        /*
         * If in dither/toggle mode the dac should be updated by an
@@ -224,10 +225,7 @@ static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input,
        else
                reg = LTC2688_CMD_CH_CODE(chan);
 
-       ret = regmap_write(st->regmap, reg, code);
-out_unlock:
-       mutex_unlock(&st->lock);
-       return ret;
+       return regmap_write(st->regmap, reg, code);
 }
 
 static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
@@ -236,20 +234,20 @@ static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input,
        struct ltc2688_chan *c = &st->channels[chan];
        int ret;
 
-       mutex_lock(&st->lock);
+       guard(mutex)(&st->lock);
        ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan),
                                 input << chan);
        if (ret)
-               goto out_unlock;
+               return ret;
 
        ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code);
-out_unlock:
-       mutex_unlock(&st->lock);
+       if (ret)
+               return ret;
 
        if (!c->toggle_chan && input == LTC2688_INPUT_B)
                *code = FIELD_GET(LTC2688_DITHER_RAW_MASK, *code);
 
-       return ret;
+       return 0;
 }
 
 static const int ltc2688_raw_range[] = {0, 1, U16_MAX};
@@ -359,17 +357,15 @@ static ssize_t ltc2688_dither_toggle_set(struct iio_dev *indio_dev,
        if (ret)
                return ret;
 
-       mutex_lock(&st->lock);
+       guard(mutex)(&st->lock);
        ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN,
                                 BIT(chan->channel), en << chan->channel);
        if (ret)
-               goto out_unlock;
+               return ret;
 
        c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT;
-out_unlock:
-       mutex_unlock(&st->lock);
 
-       return ret ?: len;
+       return len;
 }
 
 static ssize_t ltc2688_reg_bool_get(struct iio_dev *indio_dev,