diff mbox series

clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()

Message ID 20231210171907.3410922-1-visitorckw@gmail.com (mailing list archive)
State Awaiting Upstream, archived
Headers show
Series clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu() | expand

Commit Message

Kuan-Wei Chiu Dec. 10, 2023, 5:19 p.m. UTC
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(-)

Comments

Peng Fan Dec. 12, 2023, 12:40 a.m. UTC | #1
> Subject: [PATCH] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
> 
> 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>

Reviewed-by: Peng Fan <peng.fan@nxp.com>
Abel Vesa Dec. 20, 2023, 9:25 a.m. UTC | #2
On Mon, 11 Dec 2023 01:19:07 +0800, Kuan-Wei Chiu wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
      commit: 986439a9b3a32a6ac20042ec17acd443f1e7e86a

Best regards,
diff mbox series

Patch

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