Skip to contentSkip to conversation

net: dsa: sja1105: sja1105_main: Add of_node_put()

PATCH Applied Nishka Dasgupta 3 participants 3 messages Jul 23, 2019 – Jul 24, 2019

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

PATCH 1/1 net: dsa: sja1105: sja1105_main: Add of_node_put()

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

---
 drivers/net/dsa/sja1105/sja1105_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +3 -0
index 32bf3a7cc3b6..6ed5f1e35789 100644
@@ -625,6 +625,7 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,
 		if (of_property_read_u32(child, "reg", &index) < 0) {
 			dev_err(dev, "Port number not defined in device tree "
 				"(property \"reg\")\n");
+			of_node_put(child);
 			return -ENODEV;
 		}
 
@@ -634,6 +635,7 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,
 			dev_err(dev, "Failed to read phy-mode or "
 				"phy-interface-type property for port %d\n",
 				index);
+			of_node_put(child);
 			return -ENODEV;
 		}
 		ports[index].phy_mode = phy_mode;
@@ -643,6 +645,7 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,
 			if (!of_phy_is_fixed_link(child)) {
 				dev_err(dev, "phy-handle or fixed-link "
 					"properties missing!\n");
+				of_node_put(child);
 				return -ENODEV;
 			}
 			/* phy-handle is missing, but fixed-link isn't.
Signature · 1 line
2.19.1
maintainer Applied
#1 lore raw

From: Nishka Dasgupta <[email protected]>
Date: Tue, 23 Jul 2019 16:14:48 +0530

Quoted 6 lines

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

Applied.

Again, the semantics of these looping constructs are terrible.

maintainer
#2 lore raw
Quoted 9 lines · David Miller

From: Nishka Dasgupta <[email protected]>
Date: Tue, 23 Jul 2019 16:14:48 +0530

Quoted 5 lines

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return. Issue found with Coccinelle.

Quoted 5 lines
Quoted 1 line

Applied.

Again, the semantics of these looping constructs are terrible.

Strange.
Thanks for the fix.

-Vladimir