Let devres manage the netdev and the MDIO bus allocation, so that neither needs to be freed by hand in the error path and on remove. The MDIO bus itself is still registered and unregistered by hand, so that it is torn down before the MAC clocks are disabled on the probe error path. Signed-off-by: David Yang --- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c index 12a5657653f8..44b05d41cb95 100644 --- a/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +++ b/drivers/net/ethernet/hisilicon/hix5hd2_gmac.c @@ -1106,7 +1106,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) struct mii_bus *bus; int ret; - ndev = alloc_etherdev(sizeof(struct hix5hd2_priv)); + ndev = devm_alloc_etherdev(dev, sizeof(struct hix5hd2_priv)); if (!ndev) return -ENOMEM; @@ -1121,26 +1121,26 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) priv->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->base)) { ret = PTR_ERR(priv->base); - goto out_free_netdev; + return ret; } priv->ctrl_base = devm_platform_ioremap_resource(pdev, 1); if (IS_ERR(priv->ctrl_base)) { ret = PTR_ERR(priv->ctrl_base); - goto out_free_netdev; + return ret; } priv->mac_core_clk = devm_clk_get(&pdev->dev, "mac_core"); if (IS_ERR(priv->mac_core_clk)) { netdev_err(ndev, "failed to get mac core clk\n"); ret = -ENODEV; - goto out_free_netdev; + return ret; } ret = clk_prepare_enable(priv->mac_core_clk); if (ret < 0) { netdev_err(ndev, "failed to enable mac core clk %d\n", ret); - goto out_free_netdev; + return ret; } priv->mac_ifc_clk = devm_clk_get(&pdev->dev, "mac_ifc"); @@ -1175,7 +1175,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) hix5hd2_phy_reset(priv); } - bus = mdiobus_alloc(); + bus = devm_mdiobus_alloc(dev); if (bus == NULL) { ret = -ENOMEM; goto out_disable_clk; @@ -1191,7 +1191,7 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) ret = of_mdiobus_register(bus, node); if (ret) - goto err_free_mdio; + goto out_disable_clk; ret = of_get_phy_mode(node, &priv->phy_mode); if (ret) { @@ -1271,14 +1271,10 @@ static int hix5hd2_dev_probe(struct platform_device *pdev) of_node_put(priv->phy_node); err_mdiobus: mdiobus_unregister(bus); -err_free_mdio: - mdiobus_free(bus); out_disable_clk: clk_disable_unprepare(priv->mac_ifc_clk); out_disable_mac_core_clk: clk_disable_unprepare(priv->mac_core_clk); -out_free_netdev: - free_netdev(ndev); return ret; } @@ -1291,13 +1287,11 @@ static void hix5hd2_dev_remove(struct platform_device *pdev) unregister_netdev(ndev); cancel_work_sync(&priv->tx_timeout_task); mdiobus_unregister(priv->bus); - mdiobus_free(priv->bus); if (HAS_CAP_TSO(priv->hw_cap)) hix5hd2_destroy_sg_desc_queue(priv); hix5hd2_destroy_hw_desc_queue(priv); of_node_put(priv->phy_node); - free_netdev(ndev); } static const struct of_device_id hix5hd2_of_match[] = { -- 2.53.0