From: Salah Triki <salah.triki@gmail.com>
To: "Marek Behún" <kabel@kernel.org>
Cc: linux-kernel@vger.kernel.org, Salah Triki <salah.triki@gmail.com>
Subject: [PATCH] bus: moxtet: fix reference count leak in moxtet_add_device()
Date: Sat, 31 Jan 2026 10:47:48 +0100 [thread overview]
Message-ID: <20260131094748.249160-1-salah.triki@gmail.com> (raw)
If `device_add()` fails, the reference count of the device is not
dropped. This leads to a memory leak of the device and its associated
resources.
`put_device()` must be called if `device_add()` fails to properly clean up
the device structure.
Fixes: 5bc7f990cd98f ("bus: Add support for Moxtet bus")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/bus/moxtet.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c
index 7ce61d629a87..35795deba2a9 100644
--- a/drivers/bus/moxtet.c
+++ b/drivers/bus/moxtet.c
@@ -179,9 +179,11 @@ static int moxtet_add_device(struct moxtet_device *dev)
goto done;
ret = device_add(&dev->dev);
- if (ret < 0)
+ if (ret < 0) {
dev_err(dev->moxtet->dev, "can't add %s, status %d\n",
dev_name(dev->moxtet->dev), ret);
+ put_device(&dev->dev);
+ }
done:
mutex_unlock(&add_mutex);
--
2.43.0
next reply other threads:[~2026-01-31 9:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 9:47 Salah Triki [this message]
2026-02-02 13:23 ` Marek Behún
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=20260131094748.249160-1-salah.triki@gmail.com \
--to=salah.triki@gmail.com \
--cc=kabel@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®