Skip to contentSkip to conversation

clk: davinci: pll: Add of_node_put() in of_davinci_pll_init()

PATCH Applied Nishka Dasgupta 2 participants 2 messages Aug 4, 2019 – Aug 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: davinci: pll: Add of_node_put() in of_davinci_pll_init()

The variable child in the function of_davinci_pll_init takes the value of of_get_child_by_name, which gets a node but does not put it. If child is not put before the function returns it may cause a memory leak. Hence put child before two return statements.
Issue found with Coccinelle.

---
 drivers/clk/davinci/pll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/davinci/pll.c +4 -1
index 1c99e992d638..1ac11b6a47a3 100644
@@ -778,12 +778,15 @@ int of_davinci_pll_init(struct device *dev, struct device_node *node,
 		int i;
 
 		clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
-		if (!clk_data)
+		if (!clk_data) {
+			of_node_put(child);
 			return -ENOMEM;
+		}
 
 		clks = kmalloc_array(n_clks, sizeof(*clks), GFP_KERNEL);
 		if (!clks) {
 			kfree(clk_data);
+			of_node_put(child);
 			return -ENOMEM;
 		}
 
Signature · 1 line
2.19.1
maintainer Applied
#1 lore raw

Quoting Nishka Dasgupta (2019-08-04 09:28:24)

Quoted 8 lines

The variable child in the function of_davinci_pll_init takes the value of of_get_child_by_name, which gets a node but does not put it. If child is not put before the function returns it may cause a memory leak. Hence put child before two return statements.
Issue found with Coccinelle.

---

Applied to clk-next