From: Zhu Wang <wangzhu9@huawei.com>
To: <dmitry.torokhov@gmail.com>, <rafael@kernel.org>,
<christophe.jaillet@wanadoo.fr>, <gregkh@linuxfoundation.org>,
<linux-input@vger.kernel.org>
Cc: <wangzhu9@huawei.com>
Subject: [PATCH -next] Input: serio - fix possible memory leak while device_add() fails
Date: Tue, 1 Aug 2023 19:51:05 +0800 [thread overview]
Message-ID: <20230801115105.76690-1-wangzhu9@huawei.com> (raw)
If device_add() returns error, the name allocated by dev_set_name() need
be freed. As comment of device_add() says, it should use put_device() to
release the reference in the error path. So fix this by calling
put_device, then the name can be freed in kobject_cleanp().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Wang <wangzhu9@huawei.com>
---
drivers/input/serio/serio.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 767fc9efb4a8..d3bb6ec91326 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -537,10 +537,12 @@ static void serio_add_port(struct serio *serio)
serio->start(serio);
error = device_add(&serio->dev);
- if (error)
+ if (error) {
+ put_device(&serio->dev);
dev_err(&serio->dev,
"device_add() failed for %s (%s), error: %d\n",
serio->phys, serio->name, error);
+ }
}
/*
--
2.17.1
next reply other threads:[~2023-08-01 11:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 11:51 Zhu Wang [this message]
2023-08-01 23:37 ` [PATCH -next] Input: serio - fix possible memory leak while device_add() fails Dmitry Torokhov
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=20230801115105.76690-1-wangzhu9@huawei.com \
--to=wangzhu9@huawei.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-input@vger.kernel.org \
--cc=rafael@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;
as well as URLs for NNTP newsgroup(s).