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: matrix_keypad - use guard notation when acquiring spinlock

This 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.

Link: https://lore.kernel.org/r/20240825051627.2848495-12-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+8 -10
+8 -10
drivers/input/keyboard/matrix_keypad.c
··· 158 158 activate_all_cols(keypad, true); 159 159 160 160 /* Enable IRQs again */ 161 - spin_lock_irq(&keypad->lock); 162 - keypad->scan_pending = false; 163 - enable_row_irqs(keypad); 164 - spin_unlock_irq(&keypad->lock); 161 + scoped_guard(spinlock_irq, &keypad->lock) { 162 + keypad->scan_pending = false; 163 + enable_row_irqs(keypad); 164 + } 165 165 } 166 166 167 167 static irqreturn_t matrix_keypad_interrupt(int irq, void *id) 168 168 { 169 169 struct matrix_keypad *keypad = id; 170 - unsigned long flags; 171 170 172 - spin_lock_irqsave(&keypad->lock, flags); 171 + guard(spinlock_irqsave)(&keypad->lock); 173 172 174 173 /* 175 174 * See if another IRQ beaten us to it and scheduled the ··· 184 185 msecs_to_jiffies(keypad->debounce_ms)); 185 186 186 187 out: 187 - spin_unlock_irqrestore(&keypad->lock, flags); 188 188 return IRQ_HANDLED; 189 189 } 190 190 ··· 207 209 { 208 210 struct matrix_keypad *keypad = input_get_drvdata(dev); 209 211 210 - spin_lock_irq(&keypad->lock); 211 - keypad->stopped = true; 212 - spin_unlock_irq(&keypad->lock); 212 + scoped_guard(spinlock_irq, &keypad->lock) { 213 + keypad->stopped = true; 214 + } 213 215 214 216 flush_delayed_work(&keypad->work); 215 217 /*