Skip to contentSkip to conversation

net: phylink: propagate phy_attach_direct() return code

PATCH In review Russell King 3 participants 3 messages Dec 12, 2019 – Dec 15, 2019

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

PATCH 1/1 net: phylink: propagate phy_attach_direct() return code

of_phy_attach() hides the return value of phy_attach_direct(), forcing us to return a "generic" ENODEV error code that is indistinguishable from the lack-of-phy-property case.

Switch to using of_phy_find_device() to find the PHY device, and then propagating any phy_attach_direct() error back to the caller.

---
 drivers/net/phy/phylink.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/phy/phylink.c +6 -3
index f7c660bf99d1..8d20cf3ba0b7 100644
@@ -859,14 +859,17 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
 		return 0;
 	}
 
-	phy_dev = of_phy_attach(pl->netdev, phy_node, flags,
-				pl->link_interface);
+	phy_dev = of_phy_find_device(phy_node);
 	/* We're done with the phy_node handle */
 	of_node_put(phy_node);
-
 	if (!phy_dev)
 		return -ENODEV;
 
+	ret = phy_attach_direct(pl->netdev, phy_dev, flags,
+				pl->link_interface);
+	if (ret)
+		return ret;
+
 	ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
 	if (ret)
 		phy_detach(phy_dev);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Russell King

of_phy_attach() hides the return value of phy_attach_direct(), forcing us to return a "generic" ENODEV error code that is indistinguishable from the lack-of-phy-property case.

Switch to using of_phy_find_device() to find the PHY device, and then propagating any phy_attach_direct() error back to the caller.

Applied thanks, the ref counting is not entirely obvious to a layman. In your reply to Milind you said he can immediately of_node_put() because the phy_dev is never deferenced in his code, but here it looks like it is actually - the reference used to be given up after attach is done, now its given up before attach_direct is called.

But I don't know how the refcounting here works, so applied, and on the off chance the code is wrong follow up will be fine.

Quoted 25 lines
drivers/net/phy/phylink.c +6 -3
index f7c660bf99d1..8d20cf3ba0b7 100644
@@ -859,14 +859,17 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
 		return 0;
 	}
 
-	phy_dev = of_phy_attach(pl->netdev, phy_node, flags,
-				pl->link_interface);
+	phy_dev = of_phy_find_device(phy_node);
 	/* We're done with the phy_node handle */
 	of_node_put(phy_node);
-
 	if (!phy_dev)
 		return -ENODEV;
 
+	ret = phy_attach_direct(pl->netdev, phy_dev, flags,
+				pl->link_interface);
+	if (ret)
+		return ret;
+
 	ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
 	if (ret)
 		phy_detach(phy_dev);
#2 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Russell King

of_phy_attach() hides the return value of phy_attach_direct(), forcing us to return a "generic" ENODEV error code that is indistinguishable from the lack-of-phy-property case.

Switch to using of_phy_find_device() to find the PHY device, and then propagating any phy_attach_direct() error back to the caller.

Quoted 8 lines
Quoted 2 lines

Applied thanks, the ref counting is not entirely obvious to a layman. In your reply to Milind you said he can immediately of_node_put() because the phy_dev is never deferenced in his code, but here it looks like it is actually - the reference used to be given up after attach is done, now its given up before attach_direct is called.

The refcount is on the device_node - once we've got the phy device itself (or failed to) we're not using the device_node anymore, so we can put it directly after the of_phy_find_device() call.

Quoted 31 lines

But I don't know how the refcounting here works, so applied, and on the off chance the code is wrong follow up will be fine.

Quoted 25 lines
drivers/net/phy/phylink.c +6 -3
index f7c660bf99d1..8d20cf3ba0b7 100644
@@ -859,14 +859,17 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
 		return 0;
 	}
 
-	phy_dev = of_phy_attach(pl->netdev, phy_node, flags,
-				pl->link_interface);
+	phy_dev = of_phy_find_device(phy_node);
 	/* We're done with the phy_node handle */
 	of_node_put(phy_node);
-
 	if (!phy_dev)
 		return -ENODEV;
 
+	ret = phy_attach_direct(pl->netdev, phy_dev, flags,
+				pl->link_interface);
+	if (ret)
+		return ret;
+
 	ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
 	if (ret)
 		phy_detach(phy_dev);
Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up