linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/core: avoid memory leak
@ 2021-03-22 19:12 Muhammad Usama Anjum
  2021-03-22 19:18 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Muhammad Usama Anjum @ 2021-03-22 19:12 UTC (permalink / raw)
  To: Zhang Rui, Daniel Lezcano, Amit Kucheria
  Cc: musamaanjum, linux-pm, linux-kernel, kernel-janitors, colin.king,
	dan.carpenter

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal/core: avoid memory leak
  2021-03-22 19:12 [PATCH] thermal/core: avoid memory leak Muhammad Usama Anjum
@ 2021-03-22 19:18 ` Dan Carpenter
  2021-03-22 19:19   ` Muhammad Usama Anjum
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-03-22 19:18 UTC (permalink / raw)
  To: Muhammad Usama Anjum
  Cc: Zhang Rui, Daniel Lezcano, Amit Kucheria, linux-pm, linux-kernel,
	kernel-janitors, colin.king

On Tue, Mar 23, 2021 at 12:12:04AM +0500, Muhammad Usama Anjum wrote:
> 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.
> 

The patch is correct, but Daniel already sent a fix for it.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal/core: avoid memory leak
  2021-03-22 19:18 ` Dan Carpenter
@ 2021-03-22 19:19   ` Muhammad Usama Anjum
  0 siblings, 0 replies; 3+ messages in thread
From: Muhammad Usama Anjum @ 2021-03-22 19:19 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Zhang Rui, Daniel Lezcano, Amit Kucheria, linux-pm, linux-kernel,
	kernel-janitors, colin.king

On Mon, 2021-03-22 at 22:18 +0300, Dan Carpenter wrote:
> On Tue, Mar 23, 2021 at 12:12:04AM +0500, Muhammad Usama Anjum wrote:
> > 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.
> > 
> 
> The patch is correct, but Daniel already sent a fix for it.
> 
Got it. Thank you.

Thanks,
Usama
> regards,
> dan carpenter
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-22 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 19:12 [PATCH] thermal/core: avoid memory leak Muhammad Usama Anjum
2021-03-22 19:18 ` Dan Carpenter
2021-03-22 19:19   ` Muhammad Usama Anjum

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).