Skip to content

Commit cc55fc5

Browse files
chenyuan0001geertu
authored andcommitted
clk: renesas: cpg-mssr: Fix memory leak in cpg_mssr_reserved_init()
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>
1 parent 2cfff08 commit cc55fc5

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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

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

10831083
of_for_each_phandle(&it, rc, node, "clocks", "#clock-cells", -1) {
10841084
int idx;
1085+
unsigned int *new_ids;
10851086

10861087
if (it.node != priv->np)
10871088
continue;
@@ -1092,11 +1093,13 @@ static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv,
10921093
if (args[0] != CPG_MOD)
10931094
continue;
10941095

1095-
ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
1096-
if (!ids) {
1096+
new_ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL);
1097+
if (!new_ids) {
10971098
of_node_put(it.node);
1099+
kfree(ids);
10981100
return -ENOMEM;
10991101
}
1102+
ids = new_ids;
11001103

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

0 commit comments

Comments
 (0)