From: Hui Peng <benquike@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: serio - acquire device_lock(&serio->dev) in serio_bind_driver()
Date: Sat, 19 Sep 2026 20:48:16 +0000 [thread overview]
Message-ID: <20260919204816.2815952-1-benquike@gmail.com> (raw)
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
reply other threads:[~2026-09-19 20:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919204816.2815952-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®