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: xilinx_ps2 - 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-25-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+5 -10
+5 -10
drivers/input/serio/xilinx_ps2.c
··· 155 155 static int sxps2_write(struct serio *pserio, unsigned char c) 156 156 { 157 157 struct xps2data *drvdata = pserio->port_data; 158 - unsigned long flags; 159 158 u32 sr; 160 - int status = -1; 161 159 162 - spin_lock_irqsave(&drvdata->lock, flags); 160 + guard(spinlock_irqsave)(&drvdata->lock); 163 161 164 162 /* If the PS/2 transmitter is empty send a byte of data */ 165 163 sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET); 166 - if (!(sr & XPS2_STATUS_TX_FULL)) { 167 - out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); 168 - status = 0; 169 - } 164 + if (sr & XPS2_STATUS_TX_FULL) 165 + return -EAGAIN; 170 166 171 - spin_unlock_irqrestore(&drvdata->lock, flags); 172 - 173 - return status; 167 + out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); 168 + return 0; 174 169 } 175 170 176 171 /**