]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Fri, 23 Apr 2021 07:02:26 +0000 (09:02 +0200)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 4 Jan 2022 08:48:27 +0000 (09:48 +0100)
BugLink: https://bugs.launchpad.net/bugs/1951822
[ Upstream commit af9617b419f77cf0b99702a7b2b0519da0d27715 ]

If we exit the for_each_of_cpu_node loop early, the reference on the
current node must be decremented, otherwise there is a leak.

Fixes: f756e362d938 ("clk: mvebu: add CPU clock driver for Armada 7K/8K")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/545df946044fc1fc05a4217cdf0054be7a79e49e.1619161112.git.christophe.jaillet@wanadoo.fr
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/clk/mvebu/ap-cpu-clk.c

index 08ba59ec3fb17fc30dbf665f46496350029513de..71bdd7c3ff0341cd37f4d66c3f434bc225c15f1b 100644 (file)
@@ -256,12 +256,15 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
                int cpu, err;
 
                err = of_property_read_u32(dn, "reg", &cpu);
-               if (WARN_ON(err))
+               if (WARN_ON(err)) {
+                       of_node_put(dn);
                        return err;
+               }
 
                /* If cpu2 or cpu3 is enabled */
                if (cpu & APN806_CLUSTER_NUM_MASK) {
                        nclusters = 2;
+                       of_node_put(dn);
                        break;
                }
        }
@@ -288,8 +291,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
                int cpu, err;
 
                err = of_property_read_u32(dn, "reg", &cpu);
-               if (WARN_ON(err))
+               if (WARN_ON(err)) {
+                       of_node_put(dn);
                        return err;
+               }
 
                cluster_index = cpu & APN806_CLUSTER_NUM_MASK;
                cluster_index >>= APN806_CLUSTER_NUM_OFFSET;
@@ -301,6 +306,7 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
                parent = of_clk_get(np, cluster_index);
                if (IS_ERR(parent)) {
                        dev_err(dev, "Could not get the clock parent\n");
+                       of_node_put(dn);
                        return -EINVAL;
                }
                parent_name =  __clk_get_name(parent);
@@ -319,8 +325,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
                init.parent_names = &parent_name;
 
                ret = devm_clk_hw_register(dev, &ap_cpu_clk[cluster_index].hw);
-               if (ret)
+               if (ret) {
+                       of_node_put(dn);
                        return ret;
+               }
                ap_cpu_data->hws[cluster_index] = &ap_cpu_clk[cluster_index].hw;
        }