]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
clk: renesas: cpg-mssr: Fix memory leak in cpg_mssr_reserved_init()
authorYuan CHen <chenyuan@kylinos.cn>
Mon, 8 Sep 2025 01:28:10 +0000 (02:28 +0100)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 12 Sep 2025 07:52:47 +0000 (09:52 +0200)
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>
drivers/clk/renesas/renesas-cpg-mssr.c

index 5ff6ee1f7d4b7d0009769b75944883f6f6ef6aec..de1cf7ba45b78b7f37f6da9faec6fc59c6342c9d 100644 (file)
@@ -1082,6 +1082,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;
@@ -1092,11 +1093,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() */