Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: ideapad_slidebar - use guard notation when acquiring spinlock

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.

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240904044244.1042174-11-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+5 -17
+5 -17
drivers/input/misc/ideapad_slidebar.c
··· 95 95 96 96 static u8 slidebar_pos_get(void) 97 97 { 98 - u8 res; 99 - unsigned long flags; 98 + guard(spinlock_irqsave)(&io_lock); 100 99 101 - spin_lock_irqsave(&io_lock, flags); 102 100 outb(0xf4, 0xff29); 103 101 outb(0xbf, 0xff2a); 104 - res = inb(0xff2b); 105 - spin_unlock_irqrestore(&io_lock, flags); 106 - 107 - return res; 102 + return inb(0xff2b); 108 103 } 109 104 110 105 static u8 slidebar_mode_get(void) 111 106 { 112 - u8 res; 113 - unsigned long flags; 107 + guard(spinlock_irqsave)(&io_lock); 114 108 115 - spin_lock_irqsave(&io_lock, flags); 116 109 outb(0xf7, 0xff29); 117 110 outb(0x8b, 0xff2a); 118 - res = inb(0xff2b); 119 - spin_unlock_irqrestore(&io_lock, flags); 120 - 121 - return res; 111 + return inb(0xff2b); 122 112 } 123 113 124 114 static void slidebar_mode_set(u8 mode) 125 115 { 126 - unsigned long flags; 116 + guard(spinlock_irqsave)(&io_lock); 127 117 128 - spin_lock_irqsave(&io_lock, flags); 129 118 outb(0xf7, 0xff29); 130 119 outb(0x8b, 0xff2a); 131 120 outb(mode, 0xff2b); 132 - spin_unlock_irqrestore(&io_lock, flags); 133 121 } 134 122 135 123 static bool slidebar_i8042_filter(unsigned char data, unsigned char str,