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: <5d550e3c-5e18-43c7-b961-e779cc32ae03@gmail.com>
Date: Wed, 4 Sep 2024 21:22:26 +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 19/22] Input: pwm-beeper - use guard notation when
 acquiring spinlock

On 04/09/2024 06:49, Dmitry Torokhov wrote:
> Using guard notation makes the code more compact and error handling
> more robust by ensuring that locks are released in all code paths
> when control leaves critical section.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
> ---
>  drivers/input/misc/pwm-beeper.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
> index 5b9aedf4362f..0e19e97d98ec 100644
> --- a/drivers/input/misc/pwm-beeper.c
> +++ b/drivers/input/misc/pwm-beeper.c
> @@ -203,9 +203,9 @@ static int pwm_beeper_suspend(struct device *dev)
>  	 * beeper->suspended, but to ensure that pwm_beeper_event
>  	 * does not re-submit work once flag is set.
>  	 */
> -	spin_lock_irq(&beeper->input->event_lock);
> -	beeper->suspended = true;
> -	spin_unlock_irq(&beeper->input->event_lock);

I assume you know that you don't need the braces for the scoped_guard()
in these cases. If you prefer doing so to clarify (you are leaving an
empty line afterwards anyway, but still), I am ok with it.

Note that other users of scoped_guard() tend to use them without braces
for single instructions.

> +	scoped_guard(spinlock_irq, &beeper->input->event_lock) {
> +		beeper->suspended = true;
> +	}
>  
>  	pwm_beeper_stop(beeper);
>  
> @@ -216,9 +216,9 @@ static int pwm_beeper_resume(struct device *dev)
>  {
>  	struct pwm_beeper *beeper = dev_get_drvdata(dev);
>  
> -	spin_lock_irq(&beeper->input->event_lock);
> -	beeper->suspended = false;
> -	spin_unlock_irq(&beeper->input->event_lock);
> +	scoped_guard(spinlock_irq, &beeper->input->event_lock) {
> +		beeper->suspended = false;
> +	}
>  
>  	/* Let worker figure out if we should resume beeping */
>  	schedule_work(&beeper->work);

With or without braces,

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ