Message ID | 20241028-ftgmac-fixes-v1-2-b334a507be6c@codeconstruct.com.au (mailing list archive) |
---|---|
State | New |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: ethernet: ftgmac100: fixes for ncsi/phy handling on device remove | expand |
Hi Jeremy,
I checked the phy_disconnect function again.
It will assign NULL pointer to netdev->phydev after calling itself.
In NC-SI mode, it does cause a crash when calling fixed_phy_unregister(netdev->phydev).
Thank you for your help in pointing out my mistack.
Thanks,
Jacky
Reviewed-by: Jacky Chou <jacky_chou@aspeedtech.com>
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c index 9caee68468ff5f71d7ea63a0c8c9ec2be4a718bc..c6ed7ed0e2389a45a671b85ae60936df99458cd1 100644 --- a/drivers/net/ethernet/faraday/ftgmac100.c +++ b/drivers/net/ethernet/faraday/ftgmac100.c @@ -1730,16 +1730,17 @@ static int ftgmac100_setup_mdio(struct net_device *netdev) static void ftgmac100_phy_disconnect(struct net_device *netdev) { struct ftgmac100 *priv = netdev_priv(netdev); + struct phy_device *phydev = netdev->phydev; - if (!netdev->phydev) + if (!phydev) return; - phy_disconnect(netdev->phydev); + phy_disconnect(phydev); if (of_phy_is_fixed_link(priv->dev->of_node)) of_phy_deregister_fixed_link(priv->dev->of_node); if (priv->use_ncsi) - fixed_phy_unregister(netdev->phydev); + fixed_phy_unregister(phydev); } static void ftgmac100_destroy_mdio(struct net_device *netdev)
Commit e24a6c874601 ("net: ftgmac100: Get link speed and duplex for NC-SI") introduced a fixed phydev attached to the ftgmac netdev for ncsi configurations, cleaned up on remove as: phy_disconnect(netdev->phydev); /* ... */ if (priv->use_ncsi) fixed_phy_unregister(netdev->phydev); However, phy_disconnect() will clear the netdev's ->phydev pointer, so the fixed_phy_unregister() will always be invoked with a null pointer. Use a temporary for the phydev, rather than expecting the netdev->phydev point to be valid over the phy_disconnect(). Fixes: e24a6c874601 ("net: ftgmac100: Get link speed and duplex for NC-SI") Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> --- drivers/net/ethernet/faraday/ftgmac100.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)