From: Miaoqian Lin <linmq006@gmail.com>
To: Sebastian Reichel <sre@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: linmq006@gmail.com
Subject: [PATCH] power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init
Date: Fri, 28 Jan 2022 17:33:35 +0000 [thread overview]
Message-ID: <20220128173336.643-1-linmq006@gmail.com> (raw)
kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add()
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.
Fix this issue by adding kobject_put().
Fixes: c5b64a990e7f ("power: supply: ab8500: Rename charging algorithm symbols")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/power/supply/ab8500_chargalg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index c4a2fe07126c..658139797509 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1907,8 +1907,10 @@ static int ab8500_chargalg_sysfs_init(struct ab8500_chargalg *di)
ret = kobject_init_and_add(&di->chargalg_kobject,
&ab8500_chargalg_ktype,
NULL, "ab8500_chargalg");
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "failed to create sysfs entry\n");
+ kobject_put(&di->chargalg_kobject);
+ }
return ret;
}
--
2.17.1
next reply other threads:[~2022-01-28 17:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 17:33 Miaoqian Lin [this message]
2022-01-29 0:53 ` Linus Walleij
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=20220128173336.643-1-linmq006@gmail.com \
--to=linmq006@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@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
Powered by JetHome