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: <ZWpttAT6az4yYb91@google.com>
Date:   Fri, 1 Dec 2023 15:35:16 -0800
From:   Dmitry Torokhov <dmitry.torokhov@...il.com>
To:     Marcus Folkesson <marcus.folkesson@...il.com>
Cc:     linux-input@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] Input: pxrc - simplify mutex handling with guard macro

On Fri, Dec 01, 2023 at 02:17:13PM +0100, Marcus Folkesson wrote:
> Use the guard(mutex) macro for handle mutex lock/unlocks.
> 
> Signed-off-by: Marcus Folkesson <marcus.folkesson@...il.com>
> ---
> Changes in v2:
> - Add guard in pxrc_open()
> - Link to v1: https://lore.kernel.org/r/20231201-pxrc-guard-v1-1-38937e657368@gmail.com
> ---
>  drivers/input/joystick/pxrc.c | 29 ++++++++++++-----------------
>  1 file changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/input/joystick/pxrc.c b/drivers/input/joystick/pxrc.c
> index ea2bf5951d67..d4b699418361 100644
> --- a/drivers/input/joystick/pxrc.c
> +++ b/drivers/input/joystick/pxrc.c
> @@ -5,15 +5,17 @@
>   * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@...il.com>
>   */
>  
> -#include <linux/kernel.h>
> +#include <linux/cleanup.h>
>  #include <linux/errno.h>
> -#include <linux/slab.h>
> +#include <linux/input.h>
> +#include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/slab.h>
>  #include <linux/uaccess.h>
> +
>  #include <linux/usb.h>
>  #include <linux/usb/input.h>
> -#include <linux/mutex.h>
> -#include <linux/input.h>
>  
>  #define PXRC_VENDOR_ID		0x1781
>  #define PXRC_PRODUCT_ID		0x0898
> @@ -83,31 +85,26 @@ static int pxrc_open(struct input_dev *input)
>  	struct pxrc *pxrc = input_get_drvdata(input);
>  	int retval;

Now that we are not returning "success" and only carry error codes
in this variable we should call it "error".

>  
> -	mutex_lock(&pxrc->pm_mutex);
> +	guard(mutex)(&pxrc->pm_mutex);
>  	retval = usb_submit_urb(pxrc->urb, GFP_KERNEL);
>  	if (retval) {
>  		dev_err(&pxrc->intf->dev,
>  			"%s - usb_submit_urb failed, error: %d\n",
>  			__func__, retval);
> -		retval = -EIO;
> -		goto out;
> +		return -EIO;
>  	}
>  
>  	pxrc->is_open = true;
> -
> -out:
> -	mutex_unlock(&pxrc->pm_mutex);
> -	return retval;
> +	return 0;
>  }
>  
>  static void pxrc_close(struct input_dev *input)
>  {
>  	struct pxrc *pxrc = input_get_drvdata(input);
>  
> -	mutex_lock(&pxrc->pm_mutex);
> +	guard(mutex)(&pxrc->pm_mutex);
>  	usb_kill_urb(pxrc->urb);
>  	pxrc->is_open = false;
> -	mutex_unlock(&pxrc->pm_mutex);
>  }
>  
>  static void pxrc_free_urb(void *_pxrc)
> @@ -208,10 +205,9 @@ static int pxrc_suspend(struct usb_interface *intf, pm_message_t message)
>  {
>  	struct pxrc *pxrc = usb_get_intfdata(intf);
>  
> -	mutex_lock(&pxrc->pm_mutex);
> +	guard(mutex)(&pxrc->pm_mutex);
>  	if (pxrc->is_open)
>  		usb_kill_urb(pxrc->urb);
> -	mutex_unlock(&pxrc->pm_mutex);
>  
>  	return 0;
>  }
> @@ -221,11 +217,10 @@ static int pxrc_resume(struct usb_interface *intf)
>  	struct pxrc *pxrc = usb_get_intfdata(intf);
>  	int retval = 0;
>  
> -	mutex_lock(&pxrc->pm_mutex);
> +	guard(mutex)(&pxrc->pm_mutex);
>  	if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0)
>  		retval = -EIO;

		return -EIO;
>  
> -	mutex_unlock(&pxrc->pm_mutex);
>  	return retval;

	return 0;

Thanks.

-- 
Dmitry

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ