Skip to content

Commit d8ea63c

Browse files
committed
Input: sa1111ps2 - 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 424bc7e commit d8ea63c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/input/serio/sa1111ps2.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ static irqreturn_t ps2_txint(int irq, void *dev_id)
9292
struct ps2if *ps2if = dev_id;
9393
unsigned int status;
9494

95-
spin_lock(&ps2if->lock);
95+
guard(spinlock)(&ps2if->lock);
96+
9697
status = readl_relaxed(ps2if->base + PS2STAT);
9798
if (ps2if->head == ps2if->tail) {
9899
disable_irq_nosync(irq);
@@ -101,7 +102,6 @@ static irqreturn_t ps2_txint(int irq, void *dev_id)
101102
writel_relaxed(ps2if->buf[ps2if->tail], ps2if->base + PS2DATA);
102103
ps2if->tail = (ps2if->tail + 1) & (sizeof(ps2if->buf) - 1);
103104
}
104-
spin_unlock(&ps2if->lock);
105105

106106
return IRQ_HANDLED;
107107
}
@@ -113,10 +113,9 @@ static irqreturn_t ps2_txint(int irq, void *dev_id)
113113
static int ps2_write(struct serio *io, unsigned char val)
114114
{
115115
struct ps2if *ps2if = io->port_data;
116-
unsigned long flags;
117116
unsigned int head;
118117

119-
spin_lock_irqsave(&ps2if->lock, flags);
118+
guard(spinlock_irqsave)(&ps2if->lock);
120119

121120
/*
122121
* If the TX register is empty, we can go straight out.
@@ -133,7 +132,6 @@ static int ps2_write(struct serio *io, unsigned char val)
133132
}
134133
}
135134

136-
spin_unlock_irqrestore(&ps2if->lock, flags);
137135
return 0;
138136
}
139137

0 commit comments

Comments
 (0)