net: phy: fix duplicate eth_phy binding
Subsystems (2)
PATCH v2 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 zynq_phy_init() -> phy_connect() cannot attach to the already bound PHY device and creates a second instance, resulting in duplicate entries in the dm tree:
Fix this by guarding the phy_connect_phy_id() call in phy_connect() with uclass_get_device_by_phandle() to skip re-binding if the PHY node is already registered in UCLASS_ETH_PHY.
---
Changes in v2:
- Move duplicate binding check to caller phy_connect()
- Update commit description
drivers/net/phy/phy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +7 -2
@@ -938,8 +938,13 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,#endif #ifdef CONFIG_PHY_ETHERNET_ID -if (!phydev) - phydev =phy_connect_phy_id (bus, dev, addr); +if (!phydev) { +struct udevice *phy_dev; + +if (uclass_get_device_by_phandle (UCLASS_ETH_PHY , dev, +"phy-handle" , &phy_dev)) + phydev =phy_connect_phy_id (bus, dev, addr); + }#endif #ifdef CONFIG_PHY_XILINX_GMII2RGMII
Signature · 1 line
2.34.1
Quoted 27 lines · Pranav Tilak
When both
CONFIG_PHY_ETHERNET_IDandCONFIG_DM_ETH_PHYare enabled,eth_phy_binds_nodes()called frometh_post_bind()already binds the ethernet PHY node toeth_phy_generic_drv. However,phy_connect_phy_id()called viazynq_phy_init()->phy_connect()cannot attach to the already bound PHY device and creates a second instance, resulting in duplicate entries in the dm tree:Fix this by guarding the
phy_connect_phy_id()call inphy_connect()withuclass_get_device_by_phandle()to skip re-binding if the PHY node is already registered inUCLASS_ETH_PHY.Fixes 68a4d1506109 ("net: phy: Bind ETH_PHY uclass driver to each new PHY")Signed-off-by Pranav Tilak <[email protected]>---
Changes in v2:
- Move duplicate binding check to callerphy_connect()
- Update commit descriptiondrivers/net/phy/phy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/phy/phy.c +0
-0@@ -938,8 +938,13 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,#endif
drivers/net/phy/phy.c struct phy_device *phy_connect(struct mii_dev *bus, int addr, · line 946
Quoted 10 lines
drivers/net/phy/phy.c +6
-2#ifdef CONFIG_PHY_ETHERNET_ID -if (!phydev) - phydev =phy_connect_phy_id (bus, dev, addr); +if (!phydev) { +struct udevice *phy_dev; + +if (uclass_get_device_by_phandle (UCLASS_ETH_PHY , dev, +"phy-handle" , &phy_dev)) + phydev =phy_connect_phy_id (bus, dev, addr);
Shouldn't this binding check be closer to the beginning of phy_connect() ? Basically check whether the PHY driver is already bound at the beginning, and if so, you are done. I don't think that test is specific to CONFIG_PHY_ETHERNET_ID, is it ?
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Marek,
Quoted 55 lines
-----Original Message-----
From: Marek Vasut <[email protected]>
Sent: Wednesday, April 8, 2026 10:02 PM
To: Vinay Tilak, Pranav <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Jerome Forissier <[email protected]>; Tom Rini <[email protected]>; Peng Fan <[email protected]>; Lucien.Jheng <[email protected]>; Yao Zi <[email protected]>; SkyLake.Huang <[email protected]>; Siddharth Vadapalli <[email protected]>; Marek Vasut <[email protected]>; Ramon Fried <[email protected]>
Subject: Re: [PATCH v2] net: phy: fix duplicateeth_phybindingQuoted 1 line · Pranav Tilak
When both
CONFIG_PHY_ETHERNET_IDandCONFIG_DM_ETH_PHYareenabled,
drivers/net/phy/phy.c struct phy_device *phy_connect(struct mii_dev
Quoted 26 lines
eth_phy_binds_nodes()called frometh_post_bind()already binds the ethernet PHY node toeth_phy_generic_drv. However,phy_connect_phy_id()called viazynq_phy_init()->phy_connect()cannot attach to the already bound PHY device and creates a second instance, resulting in duplicate entries in the dm tree:Fix this by guarding the
phy_connect_phy_id()call inphy_connect()withuclass_get_device_by_phandle()to skip re-binding if the PHY node is already registered inUCLASS_ETH_PHY.Fixes 68a4d1506109 ("net: phy: Bind ETH_PHY uclass driver to each newPHY")
Signed-off-by Pranav Tilak <[email protected]>---
Changes in v2:
- Move duplicate binding check to callerphy_connect()
- Update commit descriptiondrivers/net/phy/phy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/phy/phy.c index renamed from drivers/net/phy/phy.c +0
-0
d7e0c4fe02d..cfca8328f1c100644drivers/net/phy/phy.c +0
-0@@ -938,8 +938,13 @@ struct phy_device *phy_connect(struct mii_dev*bus, int addr,
drivers/net/phy/phy.c struct phy_device *phy_connect(struct mii_dev *bus, int addr, · line 946
Quoted 11 lines
drivers/net/phy/phy.c +6
-2#endif #ifdef CONFIG_PHY_ETHERNET_ID -if (!phydev) - phydev =phy_connect_phy_id (bus, dev, addr); +if (!phydev) { +struct udevice *phy_dev; + +if (uclass_get_device_by_phandle (UCLASS_ETH_PHY , dev, +"phy-handle" , &phy_dev)) + phydev =phy_connect_phy_id (bus, dev, addr);
Quoted 4 lines
Shouldn't this binding check be closer to the beginning of
phy_connect()? Basically check whether the PHY driver is already bound at the beginning, and if so, you are done. I don't think that test is specific toCONFIG_PHY_ETHERNET_ID, is it ?
The check is placed inside phy_connect_phy_id() because that is the only code path that calls device_bind_driver_to_node() on the PHY node, which creates the duplicate. The other paths (phy_connect_fixed, NCSI, phy_connect_gmii2rgmii) do not bind the PHY node and are not affected.
Thanks & Regards,
Pranav Tilak
Quoted 59 lines · Pranav
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Marek,
Quoted 55 lines
-----Original Message-----
From: Marek Vasut <[email protected]>
Sent: Wednesday, April 8, 2026 10:02 PM
To: Vinay Tilak, Pranav <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Jerome Forissier <[email protected]>; Tom Rini <[email protected]>; Peng Fan <[email protected]>; Lucien.Jheng <[email protected]>; Yao Zi <[email protected]>; SkyLake.Huang <[email protected]>; Siddharth Vadapalli <[email protected]>; Marek Vasut <[email protected]>; Ramon Fried <[email protected]>
Subject: Re: [PATCH v2] net: phy: fix duplicateeth_phybindingQuoted 1 line · Pranav Tilak
When both
CONFIG_PHY_ETHERNET_IDandCONFIG_DM_ETH_PHYareenabled,
drivers/net/phy/phy.c struct phy_device *phy_connect(struct mii_dev
Quoted 26 lines
eth_phy_binds_nodes()called frometh_post_bind()already binds the ethernet PHY node toeth_phy_generic_drv. However,phy_connect_phy_id()called viazynq_phy_init()->phy_connect()cannot attach to the already bound PHY device and creates a second instance, resulting in duplicate entries in the dm tree:Fix this by guarding the
phy_connect_phy_id()call inphy_connect()withuclass_get_device_by_phandle()to skip re-binding if the PHY node is already registered inUCLASS_ETH_PHY.Fixes 68a4d1506109 ("net: phy: Bind ETH_PHY uclass driver to each newPHY")
Signed-off-by Pranav Tilak <[email protected]>---
Changes in v2:
- Move duplicate binding check to callerphy_connect()
- Update commit descriptiondrivers/net/phy/phy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/phy/phy.c index renamed from drivers/net/phy/phy.c +0
-0
d7e0c4fe02d..cfca8328f1c100644drivers/net/phy/phy.c +0
-0@@ -938,8 +938,13 @@ struct phy_device *phy_connect(struct mii_dev*bus, int addr,
Quoted 11 lines
drivers/net/phy/phy.c +6
-2#endif #ifdef CONFIG_PHY_ETHERNET_ID -if (!phydev) - phydev =phy_connect_phy_id (bus, dev, addr); +if (!phydev) { +struct udevice *phy_dev; + +if (uclass_get_device_by_phandle (UCLASS_ETH_PHY , dev, +"phy-handle" , &phy_dev)) + phydev =phy_connect_phy_id (bus, dev, addr);
Quoted 6 lines
Quoted 4 lines
Shouldn't this binding check be closer to the beginning of
phy_connect()? Basically check whether the PHY driver is already bound at the beginning, and if so, you are done. I don't think that test is specific toCONFIG_PHY_ETHERNET_ID, is it ?The check is placed inside
phy_connect_phy_id()because that is the only code path that callsdevice_bind_driver_to_node()on the PHY node, which creates the duplicate.
The device_bind_driver_to_node() in phy_connect_phy_id() is called only under very specific conditions -- if IS_ENABLED(CONFIG_DM_ETH_PHY) and phy-handle property exists and points to a valid node. The DM_ETH_PHY test is not covered here.
But that is besides the point. I think phy_connect() should figure out whether any PHY is already connected, and if it is, simply exit early. This sounds to me like a more generic solution.
Quoted 1 line
The other paths (
phy_connect_fixed, NCSI,phy_connect_gmii2rgmii) do not bind the PHY node and are not affected.
I worry this is only a matter of time, hence it would be good to have a generic solution which covers all the PHY options.