[PATCH] net: phy: only remove owned topology entries
From: Jiale Yao
Date: Wed Oct 28 2026 - 01:05:03 EST
phy_link_topo_add_phy() can fail to insert a PHY when its saved index is
already occupied. Its caller may subsequently run the normal detach
path. phy_link_topo_del_phy() then unconditionally removes the entry at
that index, including its ports, even though the entry belongs to a
different PHY.
Look up the topology entry first and only remove the PHY and its ports
when the entry belongs to the PHY being detached.
Fixes: 384968786909 ("net: phy: Introduce ethernet link topology representation")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
---
drivers/net/phy/phy_link_topology.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c
index 214ccce23cf6..175eef44cf54 100644
--- a/drivers/net/phy/phy_link_topology.c
+++ b/drivers/net/phy/phy_link_topology.c
@@ -185,6 +185,10 @@ void phy_link_topo_del_phy(struct net_device *dev,
if (!topo)
return;
+ pdn = xa_load(&topo->phys, phy->phyindex);
+ if (!pdn || pdn->phy != phy)
+ return;
+
list_for_each_entry(port, &phy->ports, head)
phy_link_topo_del_port(dev, port);
--
2.34.1