Skip to content

Commit

Permalink
net: phy: Avoid NPD upon phy_detach() when driver is unbound
Browse files Browse the repository at this point in the history
If we have unbound the PHY driver prior to calling phy_detach() (often
via phy_disconnect()) then we can cause a NULL pointer de-reference
accessing the driver owner member. The steps to reproduce are:

echo unimac-mdio-0:01 > /sys/class/net/eth0/phydev/driver/unbind
ip link set eth0 down

Fixes: cafe8df ("net: phy: Fix lack of reference count on PHY driver")
Signed-off-by: Florian Fainelli <[email protected]>
Reviewed-by: Andrew Lunn <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ffainelli authored and davem330 committed Sep 17, 2020
1 parent 19a83d3 commit c2b727d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/phy/phy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,8 @@ void phy_detach(struct phy_device *phydev)

phy_led_triggers_unregister(phydev);

module_put(phydev->mdio.dev.driver->owner);
if (phydev->mdio.dev.driver)
module_put(phydev->mdio.dev.driver->owner);

/* If the device had no specific driver before (i.e. - it
* was using the generic driver), we unbind the device
Expand Down

0 comments on commit c2b727d

Please sign in to comment.