diff mbox series

[22/22] Input: sparcspkr - use guard notation when acquiring spinlock

Message ID 20240904044938.1049843-1-dmitry.torokhov@gmail.com (mailing list archive)
State New
Headers show
Series Convert misc input drivers to use new cleanup facilities | expand

Commit Message

Dmitry Torokhov Sept. 4, 2024, 4:49 a.m. UTC
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/sparcspkr.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Javier Carrasco Sept. 4, 2024, 7:33 p.m. UTC | #1
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/sparcspkr.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
> index 20020cbc0752..5de59ae90c67 100644
> --- a/drivers/input/misc/sparcspkr.c
> +++ b/drivers/input/misc/sparcspkr.c
> @@ -69,7 +69,6 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
>  	struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
>  	struct bbc_beep_info *info = &state->u.bbc;
>  	unsigned int count = 0;
> -	unsigned long flags;
>  
>  	if (type != EV_SND)
>  		return -1;
> @@ -85,7 +84,7 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
>  
>  	count = bbc_count_to_reg(info, count);
>  
> -	spin_lock_irqsave(&state->lock, flags);
> +	guard(spinlock_irqsave)(&state->lock);
>  
>  	if (count) {
>  		sbus_writeb(0x01,                 info->regs + 0);
> @@ -97,8 +96,6 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
>  		sbus_writeb(0x00,                 info->regs + 0);
>  	}
>  
> -	spin_unlock_irqrestore(&state->lock, flags);
> -
>  	return 0;
>  }
>  
> @@ -107,7 +104,6 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
>  	struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
>  	struct grover_beep_info *info = &state->u.grover;
>  	unsigned int count = 0;
> -	unsigned long flags;
>  
>  	if (type != EV_SND)
>  		return -1;
> @@ -121,7 +117,7 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
>  	if (value > 20 && value < 32767)
>  		count = 1193182 / value;
>  
> -	spin_lock_irqsave(&state->lock, flags);
> +	guard(spinlock_irqsave)(&state->lock);
>  
>  	if (count) {
>  		/* enable counter 2 */
> @@ -136,8 +132,6 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
>  		sbus_writeb(sbus_readb(info->enable_reg) & 0xFC, info->enable_reg);
>  	}
>  
> -	spin_unlock_irqrestore(&state->lock, flags);
> -
>  	return 0;
>  }
>  

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
diff mbox series

Patch

diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index 20020cbc0752..5de59ae90c67 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -69,7 +69,6 @@  static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
 	struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
 	struct bbc_beep_info *info = &state->u.bbc;
 	unsigned int count = 0;
-	unsigned long flags;
 
 	if (type != EV_SND)
 		return -1;
@@ -85,7 +84,7 @@  static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
 
 	count = bbc_count_to_reg(info, count);
 
-	spin_lock_irqsave(&state->lock, flags);
+	guard(spinlock_irqsave)(&state->lock);
 
 	if (count) {
 		sbus_writeb(0x01,                 info->regs + 0);
@@ -97,8 +96,6 @@  static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int
 		sbus_writeb(0x00,                 info->regs + 0);
 	}
 
-	spin_unlock_irqrestore(&state->lock, flags);
-
 	return 0;
 }
 
@@ -107,7 +104,6 @@  static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
 	struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
 	struct grover_beep_info *info = &state->u.grover;
 	unsigned int count = 0;
-	unsigned long flags;
 
 	if (type != EV_SND)
 		return -1;
@@ -121,7 +117,7 @@  static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
 	if (value > 20 && value < 32767)
 		count = 1193182 / value;
 
-	spin_lock_irqsave(&state->lock, flags);
+	guard(spinlock_irqsave)(&state->lock);
 
 	if (count) {
 		/* enable counter 2 */
@@ -136,8 +132,6 @@  static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned
 		sbus_writeb(sbus_readb(info->enable_reg) & 0xFC, info->enable_reg);
 	}
 
-	spin_unlock_irqrestore(&state->lock, flags);
-
 	return 0;
 }