[PATCH 4/7] Input: gscps2 - serialize hardware and buffer access in gscps2_flush()
From: Dmitry Torokhov
Date: Sun Aug 30 2026 - 16:54:38 EST
gscps2_flush() reads from hardware registers and resets the ring buffer
indices ps2port->act and ps2port->append. In gscps2_enable(), the
trailing gscps2_flush() was called without holding ps2port->lock, racing
with concurrent hardware interrupts and buffer access.
Assert that ps2port->lock is held in gscps2_flush() with
lockdep_assert_held(), and ensure all callers acquire ps2port->lock so
that multi-step hardware sequences remain fully serialized without
unprotected windows.
Reported-by: sashiko-bot@xxxxxxxxxx
Assisted-by: LLM
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/input/serio/gscps2.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c
index fef6fffb6f86..36c25db9ff7f 100644
--- a/drivers/input/serio/gscps2.c
+++ b/drivers/input/serio/gscps2.c
@@ -228,6 +228,8 @@ static int wait_TBE(char __iomem *addr)
*/
static void gscps2_flush(struct gscps2port *ps2port)
{
+ lockdep_assert_held(&ps2port->lock);
+
while (gscps2_readb_status(ps2port->addr) & GSC_STAT_RBNE)
gscps2_readb_input(ps2port->addr);
ps2port->act = 0;
@@ -364,7 +366,8 @@ static void gscps2_enable(struct gscps2port *ps2port, bool enable)
}
wait_TBE(ps2port->addr);
- gscps2_flush(ps2port);
+ scoped_guard(spinlock_irqsave, &ps2port->lock)
+ gscps2_flush(ps2port);
}
/*
@@ -551,7 +554,8 @@ static void __exit gscps2_remove(struct parisc_device *dev)
serio_unregister_port(ps2port->port);
free_irq(dev->irq, ps2port);
- gscps2_flush(ps2port);
+ scoped_guard(spinlock_irqsave, &ps2port->lock)
+ gscps2_flush(ps2port);
iounmap(ps2port->addr);
#if 0
release_mem_region(dev->hpa, GSC_STATUS + 4);
--
2.55.0.897.gb25b4bd76c-goog