From: Linkui Xiao emac_init_phy() sets ndev->phydev by hand for a fixed link, so phy_attach_direct() never runs: the PHY stays out of the netdev's PHY link topology, and ETHTOOL_MSG_PHY_GET then dereferences a NULL link_topo in phy_prepare_data(). Use of_phy_connect(), as gianfar, fec, davinci_emac and nixge do, and as this driver already does for the phy-handle case. It attaches the PHY and drops the of_phy_find_device() reference, so put_device() goes away. It only installs emac_adjust_link() as phydev->adjust_link though, and the state machine is not started for a fixed link, so the explicit call that copies the link parameters into dev->phy stays. Attaching also means detaching. Without phy_disconnect(), unbind leaves phydev->attached_dev pointing at a freed netdev and the next probe fails with -EBUSY from phy_attach_direct(). This fixes the phy-handle path as well, which calls phy_start() but never phy_stop(). Fixes: baab9de385a8 ("net: ibm: emac: use netdev's phydev directly") Signed-off-by: Linkui Xiao --- drivers/net/ethernet/ibm/emac/core.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c index 1b95b4d5deff..ba02cf878a12 100644 --- a/drivers/net/ethernet/ibm/emac/core.c +++ b/drivers/net/ethernet/ibm/emac/core.c @@ -2673,11 +2673,16 @@ static int emac_init_phy(struct emac_instance *dev) return res; res = of_phy_register_fixed_link(np); - ndev->phydev = of_phy_find_device(np); - if (res || !ndev->phydev) - return res ? res : -EINVAL; - emac_adjust_link(dev->ndev); - put_device(&ndev->phydev->mdio.dev); + if (res) + return res; + + if (!of_phy_connect(ndev, np, &emac_adjust_link, 0, + dev->phy_mode)) { + of_phy_deregister_fixed_link(np); + return -EINVAL; + } + + emac_adjust_link(ndev); } return 0; } @@ -3190,6 +3195,10 @@ static int emac_probe(struct platform_device *ofdev) /* I have a bad feeling about this ... */ err_detach_tah: + if (ndev->phydev) + phy_disconnect(ndev->phydev); + if (of_phy_is_fixed_link(np)) + of_phy_deregister_fixed_link(np); if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) tah_detach(dev->tah_dev, dev->tah_port); err_detach_rgmii: @@ -3223,6 +3232,11 @@ static void emac_remove(struct platform_device *ofdev) cancel_work_sync(&dev->reset_work); + if (dev->ndev->phydev) + phy_disconnect(dev->ndev->phydev); + if (of_phy_is_fixed_link(ofdev->dev.of_node)) + of_phy_deregister_fixed_link(ofdev->dev.of_node); + if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) tah_detach(dev->tah_dev, dev->tah_port); if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) -- 2.25.1