Skip to content

Commit c6dcd36

Browse files
committed
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/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 54f9517 commit c6dcd36

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

drivers/input/serio/xilinx_ps2.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,17 @@ static irqreturn_t xps2_interrupt(int irq, void *dev_id)
155155
static int sxps2_write(struct serio *pserio, unsigned char c)
156156
{
157157
struct xps2data *drvdata = pserio->port_data;
158-
unsigned long flags;
159158
u32 sr;
160-
int status = -1;
161159

162-
spin_lock_irqsave(&drvdata->lock, flags);
160+
guard(spinlock_irqsave)(&drvdata->lock);
163161

164162
/* If the PS/2 transmitter is empty send a byte of data */
165163
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;
170166

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;
174169
}
175170

176171
/**

0 commit comments

Comments
 (0)