Take a refcount on the phy struct device when the phy device is attached
to a network device, and drop it after it's detached. This ensures that
a refcount is held on the phy device while the device is being used by
a network device, thereby preventing the phy_device from being
unexpectedly kfree()'d by phy_device_release().
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
* generic driver is used. The phy_device is given a ptr to
* the attaching device, and given a callback for link status
* change. The phy_device is returned to the attaching driver.
* generic driver is used. The phy_device is given a ptr to
* the attaching device, and given a callback for link status
* change. The phy_device is returned to the attaching driver.
+ * This function takes a reference on the phy device.
*/
int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
u32 flags, phy_interface_t interface)
*/
int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
u32 flags, phy_interface_t interface)
/* Assume that if there is no driver, that it doesn't
* exist, and we should use the genphy driver.
*/
/* Assume that if there is no driver, that it doesn't
* exist, and we should use the genphy driver.
*/
module_put(bus->owner);
return err;
}
module_put(bus->owner);
return err;
}
/**
* phy_detach - detach a PHY device from its network device
* @phydev: target phy_device struct
/**
* phy_detach - detach a PHY device from its network device
* @phydev: target phy_device struct
+ *
+ * This detaches the phy device from its network device and the phy
+ * driver, and drops the reference count taken in phy_attach_direct().
*/
void phy_detach(struct phy_device *phydev)
{
*/
void phy_detach(struct phy_device *phydev)
{
+ /*
+ * The phydev might go away on the put_device() below, so avoid
+ * a use-after-free bug by reading the underlying bus first.
+ */
+ put_device(&phydev->dev);
module_put(bus->owner);
}
EXPORT_SYMBOL(phy_detach);
module_put(bus->owner);
}
EXPORT_SYMBOL(phy_detach);