Skip to contentSkip to conversation

ftgmac100: Hold reference returned by of_get_child_by_name()

PATCH Superseded Liang He 2 participants 6 messages Jul 4, 2022 – Jul 7, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 ftgmac100: Hold reference returned by of_get_child_by_name()

In ftgmac100_probe(), we should hold the refernece returned by of_get_child_by_name() and use it to call of_node_put() for reference balance.

---
 drivers/net/ethernet/faraday/ftgmac100.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/faraday/ftgmac100.c +4 -2
index 5231818943c6..e50bd7beb09b 100644
@@ -1770,7 +1770,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	int irq;
 	struct net_device *netdev;
 	struct ftgmac100 *priv;
-	struct device_node *np;
+	struct device_node *np, *child_np;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1883,7 +1883,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 
 		/* Display what we found */
 		phy_attached_info(phy);
-	} else if (np && !of_get_child_by_name(np, "mdio")) {
+	} else if (np && !(child_np = of_get_child_by_name(np, "mdio"))) {
 		/* Support legacy ASPEED devicetree descriptions that decribe a
 		 * MAC with an embedded MDIO controller but have no "mdio"
 		 * child node. Automatically scan the MDIO bus for available
@@ -1901,6 +1901,8 @@ static int ftgmac100_probe(struct platform_device *pdev)
 		}
 
 	}
+	if (child_np)
+		of_node_put(child_np);
 
 	if (priv->is_aspeed) {
 		err = ftgmac100_setup_clk(priv);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 32 lines · On Mon, 4 Jul 2022 23:18:19 +0800 Liang He wrote:

In ftgmac100_probe(), we should hold the refernece returned by of_get_child_by_name() and use it to call of_node_put() for reference balance.

---
 drivers/net/ethernet/faraday/ftgmac100.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/faraday/ftgmac100.c +2 -2
index 5231818943c6..e50bd7beb09b 100644
@@ -1770,7 +1770,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	int irq;
 	struct net_device *netdev;
 	struct ftgmac100 *priv;
-	struct device_node *np;
+	struct device_node *np, *child_np;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1883,7 +1883,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 
 		/* Display what we found */
 		phy_attached_info(phy);
-	} else if (np && !of_get_child_by_name(np, "mdio")) {
+	} else if (np && !(child_np = of_get_child_by_name(np, "mdio"))) {
 		/* Support legacy ASPEED devicetree descriptions that decribe a
 		 * MAC with an embedded MDIO controller but have no "mdio"
 		 * child node. Automatically scan the MDIO bus for available

drivers/net/ethernet/faraday/ftgmac100.c static int ftgmac100_probe(struct platform_device *pdev) · line 1905

Quoted 5 lines
drivers/net/ethernet/faraday/ftgmac100.c +2 -0
@@ -1901,6 +1901,8 @@ static int ftgmac100_probe(struct platform_device *pdev)
 		}
 
 	}
+	if (child_np)
+		of_node_put(child_np);

Since we don't care about the value of the node we should add a helper which checks for presence of the node and releases the reference, rather than have to do that in this large function.

Please also add a Fixes tag.

author
#2 lore raw
Quoted 35 lines · Jakub Kicinski
Quoted 34 lines · On Mon, 4 Jul 2022 23:18:19 +0800 Liang He wrote:

In ftgmac100_probe(), we should hold the refernece returned by of_get_child_by_name() and use it to call of_node_put() for reference balance.

---
 drivers/net/ethernet/faraday/ftgmac100.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/faraday/ftgmac100.c +2 -2
index 5231818943c6..e50bd7beb09b 100644
@@ -1770,7 +1770,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	int irq;
 	struct net_device *netdev;
 	struct ftgmac100 *priv;
-	struct device_node *np;
+	struct device_node *np, *child_np;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1883,7 +1883,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 
 		/* Display what we found */
 		phy_attached_info(phy);
-	} else if (np && !of_get_child_by_name(np, "mdio")) {
+	} else if (np && !(child_np = of_get_child_by_name(np, "mdio"))) {
 		/* Support legacy ASPEED devicetree descriptions that decribe a
 		 * MAC with an embedded MDIO controller but have no "mdio"
 		 * child node. Automatically scan the MDIO bus for available
@@ -1901,6 +1901,8 @@ static int ftgmac100_probe(struct platform_device *pdev)
 		}
 
Quoted 8 lines

drivers/net/ethernet/faraday/ftgmac100.c static int ftgmac100_probe(struct platform_device *pdev) · line 1905

Quoted 3 lines
drivers/net/ethernet/faraday/ftgmac100.c +2 -0
 	}
+	if (child_np)
+		of_node_put(child_np);

Since we don't care about the value of the node we should add a helper which checks for presence of the node and releases the reference, rather than have to do that in this large function.

Thanks, I will try it.

Quoted 1 line

Please also add a Fixes tag.

Sorry, I miss the fix tag.

author
#3 lore raw
In reply to Jakub Kicinski
Quoted 43 lines · Jakub Kicinski
Quoted 32 lines · On Mon, 4 Jul 2022 23:18:19 +0800 Liang He wrote:

In ftgmac100_probe(), we should hold the refernece returned by of_get_child_by_name() and use it to call of_node_put() for reference balance.

---
 drivers/net/ethernet/faraday/ftgmac100.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/faraday/ftgmac100.c +2 -2
index 5231818943c6..e50bd7beb09b 100644
@@ -1770,7 +1770,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	int irq;
 	struct net_device *netdev;
 	struct ftgmac100 *priv;
-	struct device_node *np;
+	struct device_node *np, *child_np;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1883,7 +1883,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 
 		/* Display what we found */
 		phy_attached_info(phy);
-	} else if (np && !of_get_child_by_name(np, "mdio")) {
+	} else if (np && !(child_np = of_get_child_by_name(np, "mdio"))) {
 		/* Support legacy ASPEED devicetree descriptions that decribe a
 		 * MAC with an embedded MDIO controller but have no "mdio"
 		 * child node. Automatically scan the MDIO bus for available

drivers/net/ethernet/faraday/ftgmac100.c static int ftgmac100_probe(struct platform_device *pdev) · line 1905

Quoted 5 lines
drivers/net/ethernet/faraday/ftgmac100.c +2 -0
@@ -1901,6 +1901,8 @@ static int ftgmac100_probe(struct platform_device *pdev)
 		}
 
 	}
+	if (child_np)
+		of_node_put(child_np);

Since we don't care about the value of the node we should add a helper which checks for presence of the node and releases the reference, rather than have to do that in this large function.

Quoted 1 line

Please also add a Fixes tag.

Hi, Jakub,

Can you tell me where to add such helper?

you mean add a helper in of.h for common usasge or just add it in this file?

Thanks,

Liang

maintainer
#4 lore raw
Quoted 11 lines · On Wed, 6 Jul 2022 16:55:37 +0800 (CST) Liang He wrote:
Quoted 5 lines

Since we don't care about the value of the node we should add a helper which checks for presence of the node and releases the reference, rather than have to do that in this large function.

Please also add a Fixes tag.

Hi, Jakub,

Can you tell me where to add such helper?

you mean add a helper in of.h for common usasge or just add it in this file?

I was wondering about that. Since this is a fix let's keep it simple and add the helper directly in the same source file.

If you have more time to spend on this try searching around the tree to see if there are more places where such helper would help. If there are we can move the helper to of.h and convert the users in -next.

author
#5 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 6 Jul 2022 16:55:37 +0800 (CST) Liang He wrote:
Quoted 5 lines

Since we don't care about the value of the node we should add a helper which checks for presence of the node and releases the reference, rather than have to do that in this large function.

Please also add a Fixes tag.

Quoted 9 lines
Quoted 5 lines

Hi, Jakub,

Can you tell me where to add such helper?

you mean add a helper in of.h for common usasge or just add it in this file?

I was wondering about that. Since this is a fix let's keep it simple and add the helper directly in the same source file.

Thanks, I will first make a quick patch for this bug.

Quoted 3 lines

If you have more time to spend on this try searching around the tree to see if there are more places where such helper would help. If there are we can move the helper to of.h and convert the users in -next.

Yes, I have found many similar bugs and sent many similar patches, I would like try to make a common helper in of.h.

Thanks,

Liang