Commit a1cad5ee authored by David S. Miller's avatar David S. Miller

Merge branch 'more-phydev-leaks'

Johan Hovold says:

====================
net: fix phydev reference leaks

This series fixes a number of phydev reference leaks (and one of_node
leak) due to failure to put the reference taken by of_phy_find_device().

Note that I did not try to fix drivers/net/phy/xilinx_gmii2rgmii.c which
still leaks a reference.

Against net but should apply just as fine to net-next.

v2:
 - use put_device() instead of phy_dev_free() to put the references
   taken in net/dsa (patch 1/4).
 - add four new patches fixing similar leaks
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c9bd2823 6ffe1c4c
...@@ -542,8 +542,10 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) ...@@ -542,8 +542,10 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
/* Make sure we initialize MoCA PHYs with a link down */ /* Make sure we initialize MoCA PHYs with a link down */
if (phy_mode == PHY_INTERFACE_MODE_MOCA) { if (phy_mode == PHY_INTERFACE_MODE_MOCA) {
phydev = of_phy_find_device(dn); phydev = of_phy_find_device(dn);
if (phydev) if (phydev) {
phydev->link = 0; phydev->link = 0;
put_device(&phydev->mdio.dev);
}
} }
return 0; return 0;
......
...@@ -1107,6 +1107,9 @@ int memac_free(struct fman_mac *memac) ...@@ -1107,6 +1107,9 @@ int memac_free(struct fman_mac *memac)
{ {
free_init_resources(memac); free_init_resources(memac);
if (memac->pcsphy)
put_device(&memac->pcsphy->mdio.dev);
kfree(memac->memac_drv_param); kfree(memac->memac_drv_param);
kfree(memac); kfree(memac);
......
...@@ -892,6 +892,8 @@ static int mac_probe(struct platform_device *_of_dev) ...@@ -892,6 +892,8 @@ static int mac_probe(struct platform_device *_of_dev)
priv->fixed_link->duplex = phy->duplex; priv->fixed_link->duplex = phy->duplex;
priv->fixed_link->pause = phy->pause; priv->fixed_link->pause = phy->pause;
priv->fixed_link->asym_pause = phy->asym_pause; priv->fixed_link->asym_pause = phy->asym_pause;
put_device(&phy->mdio.dev);
} }
err = mac_dev->init(mac_dev); err = mac_dev->init(mac_dev);
......
...@@ -212,6 +212,7 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) ...@@ -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); phy_np = of_parse_phandle(np, "phy-handle", 0);
adpt->phydev = of_phy_find_device(phy_np); adpt->phydev = of_phy_find_device(phy_np);
of_node_put(phy_np);
} }
if (!adpt->phydev) { if (!adpt->phydev) {
......
...@@ -711,6 +711,8 @@ static int emac_probe(struct platform_device *pdev) ...@@ -711,6 +711,8 @@ static int emac_probe(struct platform_device *pdev)
err_undo_napi: err_undo_napi:
netif_napi_del(&adpt->rx_q.napi); netif_napi_del(&adpt->rx_q.napi);
err_undo_mdiobus: err_undo_mdiobus:
if (!has_acpi_companion(&pdev->dev))
put_device(&adpt->phydev->mdio.dev);
mdiobus_unregister(adpt->mii_bus); mdiobus_unregister(adpt->mii_bus);
err_undo_clocks: err_undo_clocks:
emac_clks_teardown(adpt); emac_clks_teardown(adpt);
...@@ -730,6 +732,8 @@ static int emac_remove(struct platform_device *pdev) ...@@ -730,6 +732,8 @@ static int emac_remove(struct platform_device *pdev)
emac_clks_teardown(adpt); emac_clks_teardown(adpt);
if (!has_acpi_companion(&pdev->dev))
put_device(&adpt->phydev->mdio.dev);
mdiobus_unregister(adpt->mii_bus); mdiobus_unregister(adpt->mii_bus);
free_netdev(netdev); free_netdev(netdev);
......
...@@ -233,6 +233,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, ...@@ -233,6 +233,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
genphy_read_status(phydev); genphy_read_status(phydev);
if (ds->ops->adjust_link) if (ds->ops->adjust_link)
ds->ops->adjust_link(ds, port, phydev); ds->ops->adjust_link(ds, port, phydev);
put_device(&phydev->mdio.dev);
} }
return 0; return 0;
...@@ -509,8 +511,9 @@ void dsa_cpu_dsa_destroy(struct device_node *port_dn) ...@@ -509,8 +511,9 @@ void dsa_cpu_dsa_destroy(struct device_node *port_dn)
if (of_phy_is_fixed_link(port_dn)) { if (of_phy_is_fixed_link(port_dn)) {
phydev = of_phy_find_device(port_dn); phydev = of_phy_find_device(port_dn);
if (phydev) { if (phydev) {
phy_device_free(phydev);
fixed_phy_unregister(phydev); fixed_phy_unregister(phydev);
put_device(&phydev->mdio.dev);
phy_device_free(phydev);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment