]> www.infradead.org Git - users/willy/xarray.git/commitdiff
clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
authorKuan-Wei Chiu <visitorckw@gmail.com>
Sun, 10 Dec 2023 17:19:07 +0000 (01:19 +0800)
committerAbel Vesa <abel.vesa@linaro.org>
Wed, 20 Dec 2023 09:32:18 +0000 (11:32 +0200)
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>
Link: https://lore.kernel.org/all/20231210171907.3410922-1-visitorckw@gmail.com/
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
drivers/clk/imx/clk-scu.c

index be89180dd19c1e7167341ed67093ffb582b2fe8d..e48a904c0013302fbe424c310266d4feea4b9940 100644 (file)
@@ -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) {