linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bernard Zhao <bernard@vivo.com>
To: Zhang Rui <rui.zhang@intel.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Amit Kucheria <amitk@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Bernard Zhao <bernard@vivo.com>
Subject: [PATCH] drivers/thermal: fix potential memleak in error branch
Date: Sun,  1 Nov 2020 18:11:48 -0800	[thread overview]
Message-ID: <20201102021149.3047-1-bernard@vivo.com> (raw)

Function __thermal_cooling_device_register, when device_register
failed, cdev is not free after error value return, this may
bring in potential memleak.

Signed-off-by: Bernard Zhao <bernard@vivo.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 3d1e0033bf3e..e4bee15dfa1f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1125,6 +1125,7 @@ __thermal_cooling_device_register(struct device_node *np,
 	if (result) {
 		ida_simple_remove(&thermal_cdev_ida, cdev->id);
 		put_device(&cdev->device);
+		kfree(cdev);
 		return ERR_PTR(result);
 	}
 
-- 
2.29.0


                 reply	other threads:[~2020-11-02  2:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201102021149.3047-1-bernard@vivo.com \
    --to=bernard@vivo.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=opensource.kernel@vivo.com \
    --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).