diff mbox series

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

Message ID 20240904044244.1042174-11-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:42 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/ideapad_slidebar.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

Comments

Javier Carrasco Sept. 4, 2024, 7:09 p.m. UTC | #1
On 04/09/2024 06:42, 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/ideapad_slidebar.c | 22 +++++-----------------
>  1 file changed, 5 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/input/misc/ideapad_slidebar.c b/drivers/input/misc/ideapad_slidebar.c
> index fa4e7f67d713..592bd159a194 100644
> --- a/drivers/input/misc/ideapad_slidebar.c
> +++ b/drivers/input/misc/ideapad_slidebar.c
> @@ -95,41 +95,29 @@ static struct platform_device *slidebar_platform_dev;
>  
>  static u8 slidebar_pos_get(void)
>  {
> -	u8 res;
> -	unsigned long flags;
> +	guard(spinlock_irqsave)(&io_lock);
>  
> -	spin_lock_irqsave(&io_lock, flags);
>  	outb(0xf4, 0xff29);
>  	outb(0xbf, 0xff2a);
> -	res = inb(0xff2b);
> -	spin_unlock_irqrestore(&io_lock, flags);
> -
> -	return res;
> +	return inb(0xff2b);
>  }
>  
>  static u8 slidebar_mode_get(void)
>  {
> -	u8 res;
> -	unsigned long flags;
> +	guard(spinlock_irqsave)(&io_lock);
>  
> -	spin_lock_irqsave(&io_lock, flags);
>  	outb(0xf7, 0xff29);
>  	outb(0x8b, 0xff2a);
> -	res = inb(0xff2b);
> -	spin_unlock_irqrestore(&io_lock, flags);
> -
> -	return res;
> +	return inb(0xff2b);
>  }
>  
>  static void slidebar_mode_set(u8 mode)
>  {
> -	unsigned long flags;
> +	guard(spinlock_irqsave)(&io_lock);
>  
> -	spin_lock_irqsave(&io_lock, flags);
>  	outb(0xf7, 0xff29);
>  	outb(0x8b, 0xff2a);
>  	outb(mode, 0xff2b);
> -	spin_unlock_irqrestore(&io_lock, flags);
>  }
>  
>  static bool slidebar_i8042_filter(unsigned char data, unsigned char str,

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

Patch

diff --git a/drivers/input/misc/ideapad_slidebar.c b/drivers/input/misc/ideapad_slidebar.c
index fa4e7f67d713..592bd159a194 100644
--- a/drivers/input/misc/ideapad_slidebar.c
+++ b/drivers/input/misc/ideapad_slidebar.c
@@ -95,41 +95,29 @@  static struct platform_device *slidebar_platform_dev;
 
 static u8 slidebar_pos_get(void)
 {
-	u8 res;
-	unsigned long flags;
+	guard(spinlock_irqsave)(&io_lock);
 
-	spin_lock_irqsave(&io_lock, flags);
 	outb(0xf4, 0xff29);
 	outb(0xbf, 0xff2a);
-	res = inb(0xff2b);
-	spin_unlock_irqrestore(&io_lock, flags);
-
-	return res;
+	return inb(0xff2b);
 }
 
 static u8 slidebar_mode_get(void)
 {
-	u8 res;
-	unsigned long flags;
+	guard(spinlock_irqsave)(&io_lock);
 
-	spin_lock_irqsave(&io_lock, flags);
 	outb(0xf7, 0xff29);
 	outb(0x8b, 0xff2a);
-	res = inb(0xff2b);
-	spin_unlock_irqrestore(&io_lock, flags);
-
-	return res;
+	return inb(0xff2b);
 }
 
 static void slidebar_mode_set(u8 mode)
 {
-	unsigned long flags;
+	guard(spinlock_irqsave)(&io_lock);
 
-	spin_lock_irqsave(&io_lock, flags);
 	outb(0xf7, 0xff29);
 	outb(0x8b, 0xff2a);
 	outb(mode, 0xff2b);
-	spin_unlock_irqrestore(&io_lock, flags);
 }
 
 static bool slidebar_i8042_filter(unsigned char data, unsigned char str,