net: qcom/emac: fix of_node and phydev leaks
authorJohan Hovold <johan@kernel.org>
Thu, 24 Nov 2016 18:21:31 +0000 (19:21 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Nov 2016 01:01:15 +0000 (20:01 -0500)
Make sure to drop the reference taken by of_phy_find_device() during
probe on probe errors and on driver unbind.

Also drop the of_node reference taken by of_parse_phandle() in the same
path.

Fixes: b9b17debc69d ("net: emac: emac gigabit ethernet controller driver")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qualcomm/emac/emac-phy.c
drivers/net/ethernet/qualcomm/emac/emac.c

index da4e90db4d989a7d9f74c45279ca36cb675b20bc..99a14df28b9634dd8e6fdeb6bc9bce2d219a3e1a 100644 (file)
@@ -212,6 +212,7 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)
 
                phy_np = of_parse_phandle(np, "phy-handle", 0);
                adpt->phydev = of_phy_find_device(phy_np);
+               of_node_put(phy_np);
        }
 
        if (!adpt->phydev) {
index 4fede4b8653861e88335759f052051e1fda9183d..57b35aeac51a0e33334319f8e5567ede3fd37ba3 100644 (file)
@@ -711,6 +711,8 @@ static int emac_probe(struct platform_device *pdev)
 err_undo_napi:
        netif_napi_del(&adpt->rx_q.napi);
 err_undo_mdiobus:
+       if (!has_acpi_companion(&pdev->dev))
+               put_device(&adpt->phydev->mdio.dev);
        mdiobus_unregister(adpt->mii_bus);
 err_undo_clocks:
        emac_clks_teardown(adpt);
@@ -730,6 +732,8 @@ static int emac_remove(struct platform_device *pdev)
 
        emac_clks_teardown(adpt);
 
+       if (!has_acpi_companion(&pdev->dev))
+               put_device(&adpt->phydev->mdio.dev);
        mdiobus_unregister(adpt->mii_bus);
        free_netdev(netdev);