lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <04336665-1766-4d93-bbe9-9b99bba48e29@baylibre.com>
Date: Tue, 3 Feb 2026 18:49:44 -0600
From: David Lechner <dlechner@...libre.com>
To: Neel Bullywon <neelb2403@...il.com>, Jonathan Cameron <jic23@...nel.org>
Cc: Nuno Sá <nuno.sa@...log.com>,
 Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH] iio: magnetometer: bmc150_magn: Used guard() for mutex
 protection

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@...il.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.

>  }
>  


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ