summaryrefslogtreecommitdiff
path: root/drivers/clk
diff options
context:
space:
mode:
authorYuan CHen <chenyuan@kylinos.cn>2025-09-08 02:28:10 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-10-19 16:33:35 +0200
commitca370366fdcdbf75f6d44e866457840126d7e8df (patch)
treecec230d2e0c164fc0568f12442843c56c445f9ea /drivers/clk
parent18a8d826b46917fb1d44346449f92e5288935390 (diff)
downloadlinux-ca370366fdcdbf75f6d44e866457840126d7e8df.tar.gz
linux-ca370366fdcdbf75f6d44e866457840126d7e8df.tar.bz2
linux-ca370366fdcdbf75f6d44e866457840126d7e8df.zip
clk: renesas: cpg-mssr: Fix memory leak in cpg_mssr_reserved_init()
[ Upstream commit cc55fc58fc1b7f405003fd2ecf79e74653461f0b ] In case of krealloc_array() failure, the current error handling just returns from the function without freeing the original array. Fix this memory leak by freeing the original array. Fixes: 6aa1754764901668 ("clk: renesas: cpg-mssr: Ignore all clocks assigned to non-Linux system") Signed-off-by: Yuan CHen <chenyuan@kylinos.cn> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20250908012810.4767-1-chenyuan_fl@163.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/renesas/renesas-cpg-mssr.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c
index 0f27c33192e1..112ed81f648e 100644
--- a/drivers/clk/renesas/renesas-cpg-mssr.c
+++ b/drivers/clk/renesas/renesas-cpg-mssr.c
@@ -1012,6 +1012,7 @@ static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv,
of_for_each_phandle(&it, rc, node, "clocks", "#clock-cells", -1) {
int idx;
+ unsigned int *new_ids;
if (it.node != priv->np)
continue;
@@ -1022,11 +1023,13 @@ static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv,
if (args[0] != CPG_MOD)
continue;
- ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
- if (!ids) {
+ new_ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
+ if (!new_ids) {
of_node_put(it.node);
+ kfree(ids);
return -ENOMEM;
}
+ ids = new_ids;
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
idx = MOD_CLK_PACK_10(args[1]); /* for DEF_MOD_STB() */