Skip to content

Commit ca37036

Browse files
chenyuan0001gregkh
authored andcommitted
clk: renesas: cpg-mssr: Fix memory leak in cpg_mssr_reserved_init()
[ Upstream commit cc55fc5 ] 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: 6aa1754 ("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>
1 parent 18a8d82 commit ca37036

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/clk/renesas/renesas-cpg-mssr.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv,
10121012

10131013
of_for_each_phandle(&it, rc, node, "clocks", "#clock-cells", -1) {
10141014
int idx;
1015+
unsigned int *new_ids;
10151016

10161017
if (it.node != priv->np)
10171018
continue;
@@ -1022,11 +1023,13 @@ static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv,
10221023
if (args[0] != CPG_MOD)
10231024
continue;
10241025

1025-
ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
1026-
if (!ids) {
1026+
new_ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
1027+
if (!new_ids) {
10271028
of_node_put(it.node);
1029+
kfree(ids);
10281030
return -ENOMEM;
10291031
}
1032+
ids = new_ids;
10301033

10311034
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
10321035
idx = MOD_CLK_PACK_10(args[1]); /* for DEF_MOD_STB() */

0 commit comments

Comments
 (0)