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: q40kbd - 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.

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

+2 -8
+2 -8
drivers/input/serio/q40kbd.c
··· 39 39 static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) 40 40 { 41 41 struct q40kbd *q40kbd = dev_id; 42 - unsigned long flags; 43 42 44 - spin_lock_irqsave(&q40kbd->lock, flags); 43 + guard(spinlock_irqsave)(&q40kbd->lock); 45 44 46 45 if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)) 47 46 serio_interrupt(q40kbd->port, master_inb(KEYCODE_REG), 0); 48 47 49 48 master_outb(-1, KEYBOARD_UNLOCK_REG); 50 - 51 - spin_unlock_irqrestore(&q40kbd->lock, flags); 52 49 53 50 return IRQ_HANDLED; 54 51 } ··· 57 60 static void q40kbd_flush(struct q40kbd *q40kbd) 58 61 { 59 62 int maxread = 100; 60 - unsigned long flags; 61 63 62 - spin_lock_irqsave(&q40kbd->lock, flags); 64 + guard(spinlock_irqsave)(&q40kbd->lock); 63 65 64 66 while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) 65 67 master_inb(KEYCODE_REG); 66 - 67 - spin_unlock_irqrestore(&q40kbd->lock, flags); 68 68 } 69 69 70 70 static void q40kbd_stop(void)