linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
@ 2023-12-10 17:19 Kuan-Wei Chiu
  2023-12-12  0:40 ` Peng Fan
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kuan-Wei Chiu @ 2023-12-10 17:19 UTC (permalink / raw)
  To: abelvesa
  Cc: peng.fan, mturquette, sboyd, shawnguo, s.hauer, kernel, festevam,
	linux-imx, linux-clk, linux-arm-kernel, linux-kernel,
	Kuan-Wei Chiu

In cases where imx_clk_is_resource_owned() returns false, the code path
does not handle the failure gracefully, potentially leading to a memory
leak. This fix ensures proper cleanup by freeing the allocated memory
for 'clk_node' before returning.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
 drivers/clk/imx/clk-scu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index be89180dd19c..e48a904c0013 100644
--- a/drivers/clk/imx/clk-scu.c
+++ b/drivers/clk/imx/clk-scu.c
@@ -886,8 +886,10 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (!imx_clk_is_resource_owned(rsrc_id))
+	if (!imx_clk_is_resource_owned(rsrc_id)) {
+		kfree(clk_node);
 		return NULL;
+	}
 
 	clk = kzalloc(sizeof(*clk), GFP_KERNEL);
 	if (!clk) {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2024-02-26 14:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-10 17:19 [PATCH] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu() Kuan-Wei Chiu
2023-12-12  0:40 ` Peng Fan
2023-12-20  9:25 ` Abel Vesa
2023-12-22  9:23 ` [PATCH] clk: imx: scu: Use common error handling code " Markus Elfring
2024-02-02 18:45   ` Abel Vesa
2024-02-02 20:21     ` Markus Elfring
2024-02-26  9:08       ` Abel Vesa
2024-02-26 14:35         ` Markus Elfring

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