net: ethernet: ucc_geth: fix fixed-link phydev leaks
authorJohan Hovold <johan@kernel.org>
Mon, 28 Nov 2016 18:25:03 +0000 (19:25 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Nov 2016 04:17:02 +0000 (23:17 -0500)
Make sure to deregister and free any fixed-link PHY registered using
of_phy_register_fixed_link() on probe errors and on driver unbind.

Fixes: 87009814cdbb ("ucc_geth: use the new fixed PHY helpers")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/ucc_geth.c

index 186ef8f16c802c5b076c41f1568ef582051cb103..f76d3327945465660508af9acdaaac4b5e90a51d 100644 (file)
@@ -3868,9 +3868,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
        dev = alloc_etherdev(sizeof(*ugeth));
 
        if (dev == NULL) {
-               of_node_put(ug_info->tbi_node);
-               of_node_put(ug_info->phy_node);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto err_deregister_fixed_link;
        }
 
        ugeth = netdev_priv(dev);
@@ -3907,10 +3906,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
                if (netif_msg_probe(ugeth))
                        pr_err("%s: Cannot register net device, aborting\n",
                               dev->name);
-               free_netdev(dev);
-               of_node_put(ug_info->tbi_node);
-               of_node_put(ug_info->phy_node);
-               return err;
+               goto err_free_netdev;
        }
 
        mac_addr = of_get_mac_address(np);
@@ -3923,16 +3919,29 @@ static int ucc_geth_probe(struct platform_device* ofdev)
        ugeth->node = np;
 
        return 0;
+
+err_free_netdev:
+       free_netdev(dev);
+err_deregister_fixed_link:
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
+       of_node_put(ug_info->tbi_node);
+       of_node_put(ug_info->phy_node);
+
+       return err;
 }
 
 static int ucc_geth_remove(struct platform_device* ofdev)
 {
        struct net_device *dev = platform_get_drvdata(ofdev);
        struct ucc_geth_private *ugeth = netdev_priv(dev);
+       struct device_node *np = ofdev->dev.of_node;
 
        unregister_netdev(dev);
        free_netdev(dev);
        ucc_geth_memclean(ugeth);
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
        of_node_put(ugeth->ug_info->tbi_node);
        of_node_put(ugeth->ug_info->phy_node);