Re: [PATCH v4 2/2] iio: accel: adxl372: convert to guard(mutex)

From: Jonathan Cameron

Date: Sat Mar 07 2026 - 12:13:31 EST


On Sat, 7 Mar 2026 17:19:12 +0530
Rajveer Chaudhari <rajveer.chaudhari.linux@xxxxxxxxx> wrote:

> Replace manual mutex_lock/mutex_unlock pair with guard(mutex) in
> adxl372_write_threshold_value(). This ensures the mutex is released
> on all return paths and allows returning directly without a goto label.
>
> Signed-off-by: Rajveer Chaudhari <rajveer.chaudhari.linux@xxxxxxxxx>
Series applied. One small tweak mentioned below.

Applied to the testing branch of iio.git where the bots poke at it
briefly before I push it out as togreg which linux-next picks up.

Thanks,

Jonathan

> ---
> v4: Changelog moved below --- as requested by Jonathan Cameron.
> v3: Return directly from error path without goto.
> v2: Split into separate patch per driver.
> ---
> drivers/iio/accel/adxl372.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
> index 28a8793a53b6..4bf8656991ea 100644
> --- a/drivers/iio/accel/adxl372.c
> +++ b/drivers/iio/accel/adxl372.c
> @@ -7,6 +7,7 @@
>
> #include <linux/bitfield.h>
> #include <linux/bitops.h>
> +#include <linux/cleanup.h>
> #include <linux/interrupt.h>
> #include <linux/irq.h>
> #include <linux/module.h>
> @@ -336,18 +337,14 @@ static ssize_t adxl372_write_threshold_value(struct iio_dev *indio_dev, unsigned
> struct adxl372_state *st = iio_priv(indio_dev);
> int ret;
>
> - mutex_lock(&st->threshold_m);
> + guard(mutex)(&st->threshold_m);
> +
> ret = regmap_write(st->regmap, addr, ADXL372_THRESH_VAL_H_SEL(threshold));
> if (ret < 0)
> - goto unlock;
> + return ret;
>
> - ret = regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5),
> + return regmap_update_bits(st->regmap, addr + 1, GENMASK(7, 5),
> ADXL372_THRESH_VAL_L_SEL(threshold) << 5);

I'd expect a minor indent update to be needed here. 1 more space.

> -
> -unlock:
> - mutex_unlock(&st->threshold_m);
> -
> - return ret;
> }
>
> static int adxl372_read_axis(struct adxl372_state *st, u8 addr)