From: Muhammad Usama Anjum <musamaanjum@gmail.com>
To: Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>
Cc: musamaanjum@gmail.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
colin.king@canonical.com, dan.carpenter@oracle.com
Subject: [PATCH] thermal/core: avoid memory leak
Date: Tue, 23 Mar 2021 00:12:04 +0500 [thread overview]
Message-ID: <20210322191204.GA2122573@LEGION> (raw)
When memory allocation for cdev is successful but ida_simple_get fails,
branch to out_kfree_cdev label happens and cdev isn't freed. There are
other some other branches in which the memory can leaked. Fix it by
freeing cdev.
Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
---
drivers/thermal/thermal_core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index c8d4010940ef..3566fd291399 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1017,6 +1017,7 @@ __thermal_cooling_device_register(struct device_node *np,
out_ida_remove:
ida_simple_remove(&thermal_cdev_ida, cdev->id);
out_kfree_cdev:
+ kfree(cdev);
return ERR_PTR(ret);
}
--
2.25.1
next reply other threads:[~2021-03-22 19:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 19:12 Muhammad Usama Anjum [this message]
2021-03-22 19:18 ` [PATCH] thermal/core: avoid memory leak Dan Carpenter
2021-03-22 19:19 ` Muhammad Usama Anjum
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=20210322191204.GA2122573@LEGION \
--to=musamaanjum@gmail.com \
--cc=amitk@kernel.org \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=daniel.lezcano@linaro.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@intel.com \
/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).