Re: [PATCH v2 2/3] iio: accel: adxl355: convert to guard(mutex)
From: David Lechner
Date: Fri Mar 06 2026 - 17:12:43 EST
On 3/6/26 3:11 PM, Rajveer Chaudhari wrote:
> ---
> drivers/iio/accel/adxl355_core.c | 27 ++++++++-------------------
> 1 file changed, 8 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c
> index 1c1d64d5cbcb..ef05178bff00 100644
> --- a/drivers/iio/accel/adxl355_core.c
> +++ b/drivers/iio/accel/adxl355_core.c
> @@ -9,6 +9,7 @@
>
> #include <linux/bits.h>
> #include <linux/bitfield.h>
> +#include <linux/cleanup.h>
> #include <linux/iio/buffer.h>
> #include <linux/iio/iio.h>
> #include <linux/iio/trigger.h>
> @@ -263,12 +264,11 @@ static int adxl355_data_rdy_trigger_set_state(struct iio_trigger *trig,
> struct adxl355_data *data = iio_priv(indio_dev);
> int ret;
>
> - mutex_lock(&data->lock);
> + guard(mutex)(&data->lock);
> ret = regmap_update_bits(data->regmap, ADXL355_POWER_CTL_REG,
> ADXL355_POWER_CTL_DRDY_MSK,
> FIELD_PREP(ADXL355_POWER_CTL_DRDY_MSK,
> state ? 0 : 1));
Same principal applies here:
return regmap_update_bits(data->regmap, ADXL355_POWER_CTL_REG,
ADXL355_POWER_CTL_DRDY_MSK,
FIELD_PREP(ADXL355_POWER_CTL_DRDY_MSK,
state ? 0 : 1));
Then we can remove `ret` entirely.
Similar changes can be made in most other functions as well.
> - mutex_unlock(&data->lock);
>
> return ret;
> }
...
> @@ -448,16 +444,15 @@ static int adxl355_set_hpf_3db(struct adxl355_data *data,
> {
> int ret;
>
> - mutex_lock(&data->lock);
> + guard(mutex)(&data->lock);
>
> if (data->hpf_3db == hpf) {
> - mutex_unlock(&data->lock);
> return 0;
> }
>
> ret = adxl355_set_op_mode(data, ADXL355_STANDBY);
> if (ret)
> - goto err_unlock;
> + return ret;
>
> ret = regmap_update_bits(data->regmap, ADXL355_FILTER_REG,
> ADXL355_FILTER_HPF_MSK,
> @@ -471,13 +466,10 @@ static int adxl355_set_hpf_3db(struct adxl355_data *data,
> if (ret)
> goto err_set_opmode;
If we aren't getting rid of all of the gotos, we are doing it wrong.
Same applies in other functions as well.
>
> - mutex_unlock(&data->lock);
> return 0;
>
> err_set_opmode:
> adxl355_set_op_mode(data, ADXL355_MEASUREMENT);
> -err_unlock:
> - mutex_unlock(&data->lock);
> return ret;
> }