net: ftgmac100: Hold reference returned by of_get_child_by_name()
Subsystems (2)
PATCH v2 1/1 net: 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.
---
changelog:
v2: (1) use a helper advised by Jakub (2) add fix tag
v1: directly hold the reference returned by of_get_xx
v1 link: https://lore.kernel.org/all/[email protected]/
NOTE: I have used an 'inline' to improve the help performance, similar with:
https://lore.kernel.org/all/[email protected]/
drivers/net/ethernet/faraday/ftgmac100.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/ethernet/faraday/ftgmac100.c +10 -1
@@ -1764,6 +1764,15 @@ static int ftgmac100_setup_clk(struct ftgmac100 *priv)return rc; } +static inline struct device_node *ftgmac100_has_child_node (struct device_node *np,const char *name) +{ +struct device_node *child_np =of_get_child_by_name (np,"mdio" ); + +of_node_put (child_np); + +return child_np; +} +static int ftgmac100_probe (struct platform_device *pdev) {struct resource *res;
@@ -1883,7 +1892,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 && !ftgmac100_has_child_node (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
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerdrivers/net/ethernet/faraday/ftgmac100.c static int ftgmac100_setup_clk(struct ftgmac100 *priv) · line 1773
Quoted 7 lines · On Sun, 10 Jul 2022 10:07:28 +0800 Liang He wrote:
drivers/net/ethernet/faraday/ftgmac100.c +7
-0+static inline struct device_node *ftgmac100_has_child_node (struct device_node *np,const char *name) +{ +struct device_node *child_np =of_get_child_by_name (np,"mdio" ); + +of_node_put (child_np); + +return child_np;
Could you make the return type bool ? We don't have a reference on the child_no node, we should probably not return the pointer.
Also the "inline" keyword is unnecessary the compiler will inline a small, static function with a single caller, anyway.
Quoted 12 lines · Jakub Kicinski
drivers/net/ethernet/faraday/ftgmac100.c static int ftgmac100_setup_clk(struct ftgmac100 *priv) · line 1773
Quoted 7 lines · On Sun, 10 Jul 2022 10:07:28 +0800 Liang He wrote:
drivers/net/ethernet/faraday/ftgmac100.c +7
-0+static inline struct device_node *ftgmac100_has_child_node (struct device_node *np,const char *name) +{ +struct device_node *child_np =of_get_child_by_name (np,"mdio" ); + +of_node_put (child_np); + +return child_np;Could you make the return type bool ? We don't have a reference on the
child_nonode, we should probably not return the pointer.
Quoted 2 lines
Also the "inline" keyword is unnecessary the compiler will inline a small, static function with a single caller, anyway.
Thanks, I will prepare the new version patch.