]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2024 07:54:49 +0000 (08:54 +0100)
[ Upstream commit 21c0efbcb45cf94724d17b040ebc03fcd4a81f22 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/clk/imx/clk-scu.c

index 1cee88b073fa247a15531fc105b0f53e2601446a..89a914a15d62d6fcc8cdf4371f2fa34d238e60c6 100644 (file)
@@ -841,8 +841,10 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na
        if (!clk_node)
                return ERR_PTR(-ENOMEM);
 
-       if (!imx_scu_clk_is_valid(rsrc_id))
+       if (!imx_scu_clk_is_valid(rsrc_id)) {
+               kfree(clk_node);
                return ERR_PTR(-EINVAL);
+       }
 
        clk = kzalloc(sizeof(*clk), GFP_KERNEL);
        if (!clk) {