net: phy: allow phy_detach() before netdev registration
Subsystems (3)
PATCH v2 1/1 net: phy: allow phy_detach() before netdev registration
From: Chenguang Zhao <[email protected]>
phylink_connect_phy() may be called from probe without RTNL while the net_device is still NETREG_UNINITIALIZED. If phylink_bringup_phy() fails, phy_detach() uses rtnl_dereference(dev->hwprov) and lockdep reports suspicious RCU usage.
hwprov cannot have been assigned before register_netdevice(). Relax the RCU check for that state only; registered devices still require RTNL.
---
v2:
phy_attach() does not set dev->hwprov. It is only written by ethtool TSCONFIG after register_netdevice(). when calling phy_detach(), we need to check whether hwprov is NULL to clean up dangling pointers.
This patch uses NETREG_UNINITIALIZED as a flag. When PHY registration fails, TSCONFIG remains unset; hence dev->hwprov should not be accessed.
v1:
https://lore.kernel.org/all/[email protected]/
drivers/net/phy/phy_device.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/phy/phy_device.c +7 -5
@@ -1941,11 +1941,13 @@ void phy_detach(struct phy_device *phydev)/* hwprov may technically be protected by ops lock but * not for devices with a phydev, see phy_link_topo_add_phy() */ - hwprov =rtnl_dereference (dev->hwprov); -/* Disable timestamp if it is the one selected */ -if (hwprov && hwprov->phydev == phydev) { -rcu_assign_pointer (dev->hwprov,NULL ); -kfree_rcu (hwprov, rcu_head); +if (dev->reg_state !=NETREG_UNINITIALIZED ) { + hwprov =rtnl_dereference (dev->hwprov); +/* Disable timestamp if it is the one selected */ +if (hwprov && hwprov->phydev == phydev) { +rcu_assign_pointer (dev->hwprov,NULL ); +kfree_rcu (hwprov, rcu_head); + } } phydev->attached_dev->phydev =NULL ;
Signature · 1 line
2.25.1
Andrew Lunn
maintainerQuoted 2 lines
phy_attach()does not setdev->hwprov. It is only written by ethtool TSCONFIG afterregister_netdevice().
Please could you point me at this code.
Andrew