Skip to content

Commit af9617b

Browse files
tititiou36bebarino
authored andcommitted
clk: mvebu: ap-cpu-clk: Fix a memory leak in error handling paths
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: f756e36 ("clk: mvebu: add CPU clock driver for Armada 7K/8K") Signed-off-by: Christophe JAILLET <[email protected]> Link: https://lore.kernel.org/r/545df946044fc1fc05a4217cdf0054be7a79e49e.1619161112.git.christophe.jaillet@wanadoo.fr Reviewed-by: Dan Carpenter <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 6880fa6 commit af9617b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

drivers/clk/mvebu/ap-cpu-clk.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,15 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
256256
int cpu, err;
257257

258258
err = of_property_read_u32(dn, "reg", &cpu);
259-
if (WARN_ON(err))
259+
if (WARN_ON(err)) {
260+
of_node_put(dn);
260261
return err;
262+
}
261263

262264
/* If cpu2 or cpu3 is enabled */
263265
if (cpu & APN806_CLUSTER_NUM_MASK) {
264266
nclusters = 2;
267+
of_node_put(dn);
265268
break;
266269
}
267270
}
@@ -288,8 +291,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
288291
int cpu, err;
289292

290293
err = of_property_read_u32(dn, "reg", &cpu);
291-
if (WARN_ON(err))
294+
if (WARN_ON(err)) {
295+
of_node_put(dn);
292296
return err;
297+
}
293298

294299
cluster_index = cpu & APN806_CLUSTER_NUM_MASK;
295300
cluster_index >>= APN806_CLUSTER_NUM_OFFSET;
@@ -301,6 +306,7 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
301306
parent = of_clk_get(np, cluster_index);
302307
if (IS_ERR(parent)) {
303308
dev_err(dev, "Could not get the clock parent\n");
309+
of_node_put(dn);
304310
return -EINVAL;
305311
}
306312
parent_name = __clk_get_name(parent);
@@ -319,8 +325,10 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
319325
init.parent_names = &parent_name;
320326

321327
ret = devm_clk_hw_register(dev, &ap_cpu_clk[cluster_index].hw);
322-
if (ret)
328+
if (ret) {
329+
of_node_put(dn);
323330
return ret;
331+
}
324332
ap_cpu_data->hws[cluster_index] = &ap_cpu_clk[cluster_index].hw;
325333
}
326334

0 commit comments

Comments
 (0)