From: Kuan-Wei Chiu Date: Sun, 10 Dec 2023 17:19:07 +0000 (+0800) Subject: clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu() X-Git-Tag: v5.15.149~237 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9709da9d10861f34cbdc00ee687471e5add3246e;p=thirdparty%2Fkernel%2Fstable.git clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu() [ 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 Reviewed-by: Peng Fan Link: https://lore.kernel.org/all/20231210171907.3410922-1-visitorckw@gmail.com/ Signed-off-by: Abel Vesa Signed-off-by: Sasha Levin --- diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index 1cee88b073fa2..89a914a15d62d 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -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) {