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] [thread-next>] [day] [month] [year] [list]
Message-ID: <c251bacb-8376-4572-b32b-27dffb03f4fc@gmail.com>
Date: Wed, 4 Sep 2024 20:49:22 +0200
From: Javier Carrasco <javier.carrasco.cruz@...il.com>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>, linux-input@...r.kernel.org
Cc: Michael Hennerich <michael.hennerich@...log.com>,
 Ville Syrjala <syrjala@....fi>,
 Support Opensource <support.opensource@...semi.com>,
 Eddie James <eajames@...ux.ibm.com>, Andrey Moiseev <o2g.org.ru@...il.com>,
 Hans de Goede <hdegoede@...hat.com>, Jeff LaBundy <jeff@...undy.com>,
 linux-kernel@...r.kernel.org,
 Javier Carrasco Cruz <javier.carrasco.cruz@...il.com>
Subject: Re: [PATCH 02/22] Input: ati_remote2 - use guard notation when
 acquiring mutex

On 04/09/2024 06:42, Dmitry Torokhov wrote:
> Using guard notation makes the code more compact and error handling
> more robust by ensuring that mutexes are released in all code paths
> when control leaves critical section.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
> ---
>  drivers/input/misc/ati_remote2.c | 57 +++++++++++---------------------
>  1 file changed, 19 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
> index 795f69edb4b2..e84649af801d 100644
> --- a/drivers/input/misc/ati_remote2.c
> +++ b/drivers/input/misc/ati_remote2.c
> @@ -244,29 +244,21 @@ static int ati_remote2_open(struct input_dev *idev)
>  	if (r) {
>  		dev_err(&ar2->intf[0]->dev,
>  			"%s(): usb_autopm_get_interface() = %d\n", __func__, r);
> -		goto fail1;
> +		return r;
>  	}
>  
> -	mutex_lock(&ati_remote2_mutex);
> +	scoped_guard(mutex, &ati_remote2_mutex) {
> +		if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
> +			r = ati_remote2_submit_urbs(ar2);
> +			if (r)
> +				break;
> +		}
>  
> -	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
> -		r = ati_remote2_submit_urbs(ar2);
> -		if (r)
> -			goto fail2;
> +		ar2->flags |= ATI_REMOTE2_OPENED;
>  	}
>  
> -	ar2->flags |= ATI_REMOTE2_OPENED;
> -
> -	mutex_unlock(&ati_remote2_mutex);
> -
>  	usb_autopm_put_interface(ar2->intf[0]);
>  
> -	return 0;
> -
> - fail2:
> -	mutex_unlock(&ati_remote2_mutex);
> -	usb_autopm_put_interface(ar2->intf[0]);
> - fail1:
>  	return r;
>  }
>  
> @@ -276,14 +268,12 @@ static void ati_remote2_close(struct input_dev *idev)
>  
>  	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
>  
> -	mutex_lock(&ati_remote2_mutex);
> +	guard(mutex)(&ati_remote2_mutex);
>  
>  	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
>  		ati_remote2_kill_urbs(ar2);
>  
>  	ar2->flags &= ~ATI_REMOTE2_OPENED;
> -
> -	mutex_unlock(&ati_remote2_mutex);
>  }
>  
>  static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
> @@ -713,16 +703,14 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev,
>  		return r;
>  	}
>  
> -	mutex_lock(&ati_remote2_mutex);
> -
> -	if (mask != ar2->channel_mask) {
> -		r = ati_remote2_setup(ar2, mask);
> -		if (!r)
> -			ar2->channel_mask = mask;
> +	scoped_guard(mutex, &ati_remote2_mutex) {
> +		if (mask != ar2->channel_mask) {
> +			r = ati_remote2_setup(ar2, mask);
> +			if (!r)
> +				ar2->channel_mask = mask;
> +		}
>  	}
>  
> -	mutex_unlock(&ati_remote2_mutex);
> -
>  	usb_autopm_put_interface(ar2->intf[0]);
>  
>  	return r ? r : count;
> @@ -892,15 +880,13 @@ static int ati_remote2_suspend(struct usb_interface *interface,
>  
>  	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
>  
> -	mutex_lock(&ati_remote2_mutex);
> +	guard(mutex)(&ati_remote2_mutex);
>  
>  	if (ar2->flags & ATI_REMOTE2_OPENED)
>  		ati_remote2_kill_urbs(ar2);
>  
>  	ar2->flags |= ATI_REMOTE2_SUSPENDED;
>  
> -	mutex_unlock(&ati_remote2_mutex);
> -
>  	return 0;
>  }
>  
> @@ -917,7 +903,7 @@ static int ati_remote2_resume(struct usb_interface *interface)
>  
>  	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
>  
> -	mutex_lock(&ati_remote2_mutex);
> +	guard(mutex)(&ati_remote2_mutex);
>  
>  	if (ar2->flags & ATI_REMOTE2_OPENED)
>  		r = ati_remote2_submit_urbs(ar2);
> @@ -925,8 +911,6 @@ static int ati_remote2_resume(struct usb_interface *interface)
>  	if (!r)
>  		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
>  
> -	mutex_unlock(&ati_remote2_mutex);
> -
>  	return r;
>  }
>  
> @@ -943,11 +927,11 @@ static int ati_remote2_reset_resume(struct usb_interface *interface)
>  
>  	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
>  
> -	mutex_lock(&ati_remote2_mutex);
> +	guard(mutex)(&ati_remote2_mutex);
>  
>  	r = ati_remote2_setup(ar2, ar2->channel_mask);
>  	if (r)
> -		goto out;
> +		return r;
>  
>  	if (ar2->flags & ATI_REMOTE2_OPENED)
>  		r = ati_remote2_submit_urbs(ar2);
> @@ -955,9 +939,6 @@ static int ati_remote2_reset_resume(struct usb_interface *interface)
>  	if (!r)
>  		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
>  
> - out:
> -	mutex_unlock(&ati_remote2_mutex);
> -
>  	return r;
>  }
>  

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ