Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>

authored by

Christophe JAILLET and committed by
Stephen Boyd
af9617b4 6880fa6c

+11 -3
+11 -3
drivers/clk/mvebu/ap-cpu-clk.c
··· 256 256 int cpu, err; 257 257 258 258 err = of_property_read_u32(dn, "reg", &cpu); 259 - if (WARN_ON(err)) 259 + if (WARN_ON(err)) { 260 + of_node_put(dn); 260 261 return err; 262 + } 261 263 262 264 /* If cpu2 or cpu3 is enabled */ 263 265 if (cpu & APN806_CLUSTER_NUM_MASK) { 264 266 nclusters = 2; 267 + of_node_put(dn); 265 268 break; 266 269 } 267 270 } ··· 291 288 int cpu, err; 292 289 293 290 err = of_property_read_u32(dn, "reg", &cpu); 294 - if (WARN_ON(err)) 291 + if (WARN_ON(err)) { 292 + of_node_put(dn); 295 293 return err; 294 + } 296 295 297 296 cluster_index = cpu & APN806_CLUSTER_NUM_MASK; 298 297 cluster_index >>= APN806_CLUSTER_NUM_OFFSET; ··· 306 301 parent = of_clk_get(np, cluster_index); 307 302 if (IS_ERR(parent)) { 308 303 dev_err(dev, "Could not get the clock parent\n"); 304 + of_node_put(dn); 309 305 return -EINVAL; 310 306 } 311 307 parent_name = __clk_get_name(parent); ··· 325 319 init.parent_names = &parent_name; 326 320 327 321 ret = devm_clk_hw_register(dev, &ap_cpu_clk[cluster_index].hw); 328 - if (ret) 322 + if (ret) { 323 + of_node_put(dn); 329 324 return ret; 325 + } 330 326 ap_cpu_data->hws[cluster_index] = &ap_cpu_clk[cluster_index].hw; 331 327 } 332 328