Skip to contentSkip to conversation

clk: versatile: Add of_node_put() before return statement

PATCH Applied Sumera Priyadarsini 3 participants 3 messages Aug 29, 2020 – Sep 10, 2020

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

PATCH 1/1 clk: versatile: Add of_node_put() before return statement

Every iteration of for_each_available_child_of_node() decrements the reference count of the previous node, however when control is transferred from the middle of the loop, as in the case of a return or break or goto, there is no decrement thus ultimately resulting in a memory leak.

Fix a potential memory leak in clk-impd1.c by inserting of_node_put() before a return statement.

Issue found with Coccinelle.

---
 drivers/clk/versatile/clk-impd1.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/versatile/clk-impd1.c +3 -1
index ca798249544d..85c395df9c00 100644
@@ -109,8 +109,10 @@ static int integrator_impd1_clk_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child) {
 		ret = integrator_impd1_clk_spawn(dev, np, child);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			break;
+		}
 	}
 
 	return ret;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Sumera Priyadarsini

Every iteration of for_each_available_child_of_node() decrements the reference count of the previous node, however when control is transferred from the middle of the loop, as in the case of a return or break or goto, there is no decrement thus ultimately resulting in a memory leak.

Quoted 6 lines

Fix a potential memory leak in clk-impd1.c by inserting of_node_put() before a return statement.

Issue found with Coccinelle.

Yours,
Linus Walleij

maintainer Applied
#2 lore raw
In reply to Sumera Priyadarsini

Quoting Sumera Priyadarsini (2020-08-29 10:57:04)

Quoted 6 lines

Every iteration of for_each_available_child_of_node() decrements the reference count of the previous node, however when control is transferred from the middle of the loop, as in the case of a return or break or goto, there is no decrement thus ultimately resulting in a memory leak.

Quoted 7 lines

Fix a potential memory leak in clk-impd1.c by inserting of_node_put() before a return statement.

Issue found with Coccinelle.

---

Applied to clk-fixes