mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Input: serio - acquire device_lock(&serio->dev) in serio_bind_driver()
@ 2026-09-19 20:48 Hui Peng
  0 siblings, 0 replies; only message in thread
From: Hui Peng @ 2026-09-19 20:48 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel

drvctl_store() calls serio_bind_driver(serio, drv) under serio_mutex
without holding device_lock(&serio->dev). Because sysfs driver bind and
unbind attributes (/sys/bus/serio/drivers/<drv>/bind and unbind)
serialize via device_lock(&serio->dev) without acquiring serio_mutex,
serio_bind_driver() can race concurrently with bind_store() or
unbind_store(), causing duplicate sysfs link creation warnings
(sysfs_warn_dup / -EEXIST) or NULL pointer dereferences in klist_put().

Acquire guard(device)(&serio->dev) in serio_bind_driver() and check
serio->dev.driver before binding.

Fixes: 0a66045bcfd3 ("Input: serio core - handle errors returned by device_bind_driver()")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -83,6 +83,11 @@ static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
 {
 	int error;
 
+	guard(device)(&serio->dev);
+
+	if (serio->dev.driver)
+		return serio->dev.driver == &drv->driver ? 0 : -EBUSY;
+
 	if (serio_match_port(drv->id_table, serio)) {
 
 		serio->dev.driver = &drv->driver;
-- 
2.43.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-19 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 20:48 [PATCH] Input: serio - acquire device_lock(&serio->dev) in serio_bind_driver() Hui Peng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®