Linux IIO development
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Rajveer Chaudhari <rajveer.chaudhari.linux@gmail.com>,
	lucas.p.stankus@gmail.com, lars@metafoo.de,
	Michael.Hennerich@analog.com, jic23@kernel.org,
	nuno.sa@analog.com, andy@kernel.org, puranjay@kernel.org
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] iio: accel: adxl355: convert to guard(mutex)
Date: Fri, 6 Mar 2026 16:12:35 -0600	[thread overview]
Message-ID: <8f532495-868b-4e69-bec0-0e6e12b7b959@baylibre.com> (raw)
In-Reply-To: <20260306211152.65109-3-rajveer.chaudhari.linux@gmail.com>

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;
>  }

  reply	other threads:[~2026-03-06 22:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06 20:26 [PATCH] iio: convert to guard(mutex) Rajveer Chaudhari
2026-03-06 20:37 ` David Lechner
2026-03-06 21:11   ` [PATCH v2 0/3] iio: accel: " Rajveer Chaudhari
2026-03-06 21:11     ` [PATCH v2 1/3] iio: accel: adxl313: " Rajveer Chaudhari
2026-03-06 22:10       ` David Lechner
2026-03-06 21:11     ` [PATCH v2 2/3] iio: accel: adxl355: " Rajveer Chaudhari
2026-03-06 22:12       ` David Lechner [this message]
2026-03-06 21:11     ` [PATCH v2 3/3] iio: accel: adxl372: " Rajveer Chaudhari
2026-03-07 10:17     ` [PATCH v3 0/3] iio: accel: " Rajveer Chaudhari
2026-03-07 10:17       ` [PATCH v3 1/3] iio: accel: adxl313: " Rajveer Chaudhari
2026-03-07 10:31         ` Jonathan Cameron
2026-03-07 10:17       ` [PATCH v3 2/3] iio: accel: adxl355: " Rajveer Chaudhari
2026-03-07 10:39         ` Jonathan Cameron
2026-03-07 10:43           ` Jonathan Cameron
2026-03-07 10:17       ` [PATCH v3 3/3] iio: accel: adxl372: " Rajveer Chaudhari
2026-03-07 10:41         ` Jonathan Cameron
2026-03-07 10:26       ` [PATCH v3 0/3] iio: accel: " Jonathan Cameron
2026-03-07 10:33         ` Rajveer Chaudhari
2026-03-07 17:08           ` Jonathan Cameron
2026-03-06 21:12 ` [PATCH] iio: " Andy Shevchenko
2026-03-06 21:23   ` Rajveer Chaudhari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f532495-868b-4e69-bec0-0e6e12b7b959@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.p.stankus@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=puranjay@kernel.org \
    --cc=rajveer.chaudhari.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox