From: Guangshuo Li <lgs201920130244@gmail.com>
To: "Thorsten Scherer" <t.scherer@eckelmann.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>, stable@vger.kernel.org
Subject: [PATCH] siox: fix master memory leak on registration failure
Date: Sun, 20 Sep 2026 02:10:51 +0800 [thread overview]
Message-ID: <20260919181051.3751829-1-lgs201920130244@gmail.com> (raw)
siox_master_register() takes an additional reference on the master
device with get_device() so that the SIOX core owns a reference until
siox_master_unregister() is called.
If kthread_run() fails, siox_master_register() returns without dropping
this reference. Similarly, if device_add() fails, the poll thread is
stopped but the reference acquired by siox_master_register() is not
released.
For devm-allocated masters, the devres cleanup only drops the original
allocation reference. The additional registration reference therefore
remains held, preventing siox_master_release() from being called and
leaking the siox_master allocation.
Drop the reference acquired by siox_master_register() on both failure
paths. On device_add() failure, kthread_stop() first lets the poll thread
drop its own reference before the registration reference is released.
The issue was identified by a static analysis tool I developed and
confirmed by manual review.
Fixes: 2c12932b8e65 ("siox: Don't pass the reference on a master in siox_master_register()")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/siox/siox-core.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/siox/siox-core.c b/drivers/siox/siox-core.c
index 3e8f3b6a4555..ea1ef0a5c991 100644
--- a/drivers/siox/siox-core.c
+++ b/drivers/siox/siox-core.c
@@ -753,14 +753,21 @@ int siox_master_register(struct siox_master *smaster)
smaster->poll_thread = kthread_run(siox_poll_thread, smaster,
"siox-%d", smaster->busno);
if (IS_ERR(smaster->poll_thread)) {
+ ret = PTR_ERR(smaster->poll_thread);
smaster->active = 0;
- return PTR_ERR(smaster->poll_thread);
+ goto err_put_device;
}
ret = device_add(&smaster->dev);
- if (ret)
+ if (ret) {
kthread_stop(smaster->poll_thread);
+ goto err_put_device;
+ }
+ return 0;
+
+err_put_device:
+ put_device(&smaster->dev);
return ret;
}
EXPORT_SYMBOL_GPL(siox_master_register);
--
2.43.0
next reply other threads:[~2026-09-19 18:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 18:10 Guangshuo Li [this message]
2026-09-21 10:51 ` Markus Elfring
2026-09-21 13:02 ` Uwe Kleine-König
2026-09-24 13:05 ` Thorsten Scherer
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=20260919181051.3751829-1-lgs201920130244@gmail.com \
--to=lgs201920130244@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=t.scherer@eckelmann.de \
--cc=u.kleine-koenig@pengutronix.de \
/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®