Skip to contentSkip to conversation

net: phy: fix duplicate eth_phy binding

PATCH Superseded Pranav Tilak 2 participants 2 messages Apr 21 – Apr 22

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: phy: fix duplicate eth_phy binding

When both CONFIG_PHY_ETHERNET_ID and CONFIG_DM_ETH_PHY are enabled, eth_phy_binds_nodes() called from eth_post_bind() already binds the ethernet PHY node to eth_phy_generic_drv. However, phy_connect_phy_id() called via phy_connect() also binds the same PHY node, resulting in duplicate entries in the DM tree.

Fix this by checking at the beginning of phy_connect() whether the PHY is already bound via uclass_get_device_by_phandle(). If so, skip all generic binding methods.

Fixes 68a4d1506109 ("net: phy: Bind ETH_PHY uclass driver to each new PHY")

---
Changes in v3:
- Moved duplicate binding check to beginning of phy_connect()

Changes in v2:
- Move duplicate binding check to caller phy_connect()
- Update commit description

 drivers/net/phy/phy.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/phy/phy.c +6 -0
index d7e0c4fe02d..b1eb5173fe8 100644
@@ -927,7 +927,12 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
 {
 	struct phy_device *phydev = NULL;
 	uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
+	struct udevice *phy_dev;
 
+	/* Skip binding if PHY already bound by eth_phy_binds_nodes(). */
+	if (!IS_ENABLED(CONFIG_DM_ETH_PHY) ||
+	    uclass_get_device_by_phandle(UCLASS_ETH_PHY, dev,
+					 "phy-handle", &phy_dev)) {
 #ifdef CONFIG_PHY_FIXED
 	phydev = phy_connect_fixed(bus, dev);
 #endif
@@ -946,6 +951,7 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
 	if (!phydev)
 		phydev = phy_connect_gmii2rgmii(bus, dev);
 #endif
+	}
 
 	if (!phydev)
 		phydev = phy_find_by_mask(bus, mask);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 28 lines · Pranav Tilak

When both CONFIG_PHY_ETHERNET_ID and CONFIG_DM_ETH_PHY are enabled, eth_phy_binds_nodes() called from eth_post_bind() already binds the ethernet PHY node to eth_phy_generic_drv. However, phy_connect_phy_id() called via phy_connect() also binds the same PHY node, resulting in duplicate entries in the DM tree.

Fix this by checking at the beginning of phy_connect() whether the PHY is already bound via uclass_get_device_by_phandle(). If so, skip all generic binding methods.

Fixes 68a4d1506109 ("net: phy: Bind ETH_PHY uclass driver to each new PHY")

---
Changes in v3:
- Moved duplicate binding check to beginning of phy_connect()

Changes in v2:
- Move duplicate binding check to caller phy_connect()
- Update commit description

  drivers/net/phy/phy.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/net/phy/phy.c +0 -0
index d7e0c4fe02d..b1eb5173fe8 100644

drivers/net/phy/phy.c struct phy_device *phy_connect(struct mii_dev *bus, int addr, · line 935

Quoted 9 lines
drivers/net/phy/phy.c +5 -0
@@ -927,7 +927,12 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
  {
  	struct phy_device *phydev = NULL;
  	uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
+	struct udevice *phy_dev;
 
+	/* Skip binding if PHY already bound by eth_phy_binds_nodes(). */
+	if (!IS_ENABLED(CONFIG_DM_ETH_PHY) ||
+	    uclass_get_device_by_phandle(UCLASS_ETH_PHY, dev,
+					 "phy-handle", &phy_dev)) {

You can not simply disable the phy_connect() code if DM_ETH_PHY is enabled, that will break a lot of users. There has to be some runtime check here to determine whether a PHY is already connected or not.