mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Neel Bullywon <neelb2403@gmail.com>, Jonathan Cameron <jic23@kernel.org>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: magnetometer: bmc150_magn: Used guard() for mutex protection
Date: Tue, 3 Feb 2026 18:49:44 -0600	[thread overview]
Message-ID: <04336665-1766-4d93-bbe9-9b99bba48e29@baylibre.com> (raw)
In-Reply-To: <20260204000350.25454-1-neelb2403@gmail.com>

On 2/3/26 6:03 PM, Neel Bullywon wrote:
> Replaced the manual mutex lock/unlock calls using guard() to simplify
> the error handling and reduce goto statement usage.
> 
> By using RAII-style cleanup, it ensures the mutex is always released
> when exiting the function, regardless of the return path taken
> 
> This was compiled test only
> 
> Signed-off-by: Neel Bullywon <neelb2403@gmail.com>
> ---
>  drivers/iio/magnetometer/bmc150_magn.c | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index 6a73f6e2f1f0..73d9183a354b 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -796,29 +796,22 @@ static int bmc150_magn_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  	struct bmc150_magn_data *data = iio_priv(indio_dev);
>  	int ret = 0;

We can take this a bit farther and drop the init here.

>  
> -	mutex_lock(&data->mutex);
> +	guard(mutex)(&data->mutex);
> +
>  	if (state == data->dready_trigger_on)
> -		goto err_unlock;
> +		return 0;
>  
>  	ret = regmap_update_bits(data->regmap, BMC150_MAGN_REG_INT_DRDY,
>  				 BMC150_MAGN_MASK_DRDY_EN,
>  				 state << BMC150_MAGN_SHIFT_DRDY_EN);
>  	if (ret < 0)
> -		goto err_unlock;
> +		return ret;
>  
>  	data->dready_trigger_on = state;
>  
> -	if (state) {
> +	if (state)
>  		ret = bmc150_magn_reset_intr(data);

return directly here

> -		if (ret < 0)
> -			goto err_unlock;
> -	}
> -	mutex_unlock(&data->mutex);
>  
> -	return 0;
> -
> -err_unlock:
> -	mutex_unlock(&data->mutex);
>  	return ret;

and return 0 here.

>  }
>  


      reply	other threads:[~2026-02-04  0:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04  0:03 Neel Bullywon
2026-02-04  0:49 ` David Lechner [this message]

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=04336665-1766-4d93-bbe9-9b99bba48e29@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=andy@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neelb2403@gmail.com \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®