Re: [PATCH 19/22] Input: pwm-beeper - use guard notation when acquiring spinlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> ---
>  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@xxxxxxxxx>




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux