Message ID | 20240904044914.1049280-1-dmitry.torokhov@gmail.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | 5bd3ade12109b276337ce85b950e09e09043e748 |
Headers | show |
Series | Convert misc input drivers to use new cleanup facilities | expand |
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@gmail.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@gmail.com>
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); + 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);
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@gmail.com> --- drivers/input/misc/pwm-beeper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)