net: fix phydev reference leaks
Subsystems (6)
v2 cover 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.
Thanks,
Johan
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
Johan Hovold (5):
net: dsa: fix fixed-link-phy device leaks
net: bcmgenet: fix phydev reference leak
net: fsl/fman: fix phydev reference leak
net: fsl/fman: fix fixed-link-phydev reference leak
net: qcom/emac: fix of_node and phydev leaks
drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 +++- drivers/net/ethernet/freescale/fman/fman_memac.c | 3 +++ drivers/net/ethernet/freescale/fman/mac.c | 2 ++ drivers/net/ethernet/qualcomm/emac/emac-phy.c | 1 + drivers/net/ethernet/qualcomm/emac/emac.c | 4 ++++ net/dsa/dsa.c | 5 ++++- 6 files changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.3
PATCH v2 1/5 net: dsa: fix fixed-link-phy device leaks
Make sure to drop the reference taken by of_phy_find_device() when registering and deregistering the fixed-link PHY-device.
speeds/duplex")
--- net/dsa/dsa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/dsa/dsa.c +4 -1
@@ -233,6 +233,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,genphy_read_status (phydev);if (ds->ops->adjust_link) ds->ops->adjust_link (ds, port, phydev); + +put_device (&phydev->mdio.dev); }return 0 ;
@@ -509,8 +511,9 @@ void dsa_cpu_dsa_destroy(struct device_node *port_dn)if (of_phy_is_fixed_link (port_dn)) { phydev =of_phy_find_device (port_dn);if (phydev) { -phy_device_free (phydev);fixed_phy_unregister (phydev); +put_device (&phydev->mdio.dev); +phy_device_free (phydev); } } }
Signature · 1 line
2.7.3
PATCH v2 2/5 net: bcmgenet: fix phydev reference leak
In reply to Johan HovoldMake sure to drop the reference taken by of_phy_find_device() when initialising MOCA PHYs.
all MoCA PHYs")
--- drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/genet/bcmmii.c +3 -1
@@ -542,8 +542,10 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)/* Make sure we initialize MoCA PHYs with a link down */ if (phy_mode ==PHY_INTERFACE_MODE_MOCA ) { phydev =of_phy_find_device (dn); -if (phydev) +if (phydev) { phydev->link =0 ; +put_device (&phydev->mdio.dev); + } }return 0 ;
Signature · 1 line
2.7.3
PATCH v2 3/5 net: fsl/fman: fix phydev reference leak
In reply to Johan HovoldMake sure to drop the reference taken by of_phy_find_device() during initialisation when later freeing the struct fman_mac.
--- drivers/net/ethernet/freescale/fman/fman_memac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/freescale/fman/fman_memac.c +3 -0
@@ -1107,6 +1107,9 @@ int memac_free(struct fman_mac *memac) {free_init_resources (memac); +if (memac->pcsphy) +put_device (&memac->pcsphy->mdio.dev); +kfree (memac->memac_drv_param);kfree (memac);
Signature · 1 line
2.7.3
PATCH v2 4/5 net: fsl/fman: fix fixed-link-phydev reference leak
In reply to Johan HovoldMake sure to drop the reference taken by of_phy_find_device() when looking up a fixed-link phydev during probe.
--- drivers/net/ethernet/freescale/fman/mac.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/freescale/fman/mac.c +2 -0
@@ -892,6 +892,8 @@ static int mac_probe(struct platform_device *_of_dev) priv->fixed_link->duplex = phy->duplex; priv->fixed_link->pause = phy->pause; priv->fixed_link->asym_pause = phy->asym_pause; + +put_device (&phy->mdio.dev); } err = mac_dev->init (mac_dev);
Signature · 1 line
2.7.3
Madalin-Cristian Bucur
maintainerRE: [PATCH net v2 4/5] net: fsl/fman: fix fixed-link-phydev reference leak
Quoted 28 lines
-----Original Message-----
From: Johan Hovold [mailto:[email protected]] On Behalf Of Johan Hovold
Sent: Thursday, November 24, 2016 8:22 PMMake sure to drop the reference taken by
of_phy_find_device()when looking up a fixed-link phydev during probe.Fixes 57ba4c9b56d8 ("fsl/fman: Add FMan MAC support")Signed-off-by Johan Hovold <[email protected]>--- drivers/net/ethernet/freescale/fman/mac.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/freescale/fman/mac.c +2
-1@@ -892,6 +892,8 @@ static int mac_probe(struct platform_device *_of_dev) priv->fixed_link->duplex = phy->duplex; priv->fixed_link->pause = phy->pause; priv->fixed_link->asym_pause = phy->asym_pause; + +put_device (&phy->mdio.dev); } err = mac_dev->init (mac_dev); --
Quoted 1 line
2.7.3
Thank you,
Madalin
PATCH v2 5/5 net: qcom/emac: fix of_node and phydev leaks
In reply to Johan HovoldMake 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.
--- drivers/net/ethernet/qualcomm/emac/emac-phy.c | 1 + drivers/net/ethernet/qualcomm/emac/emac.c | 4 ++++ 2 files changed, 5 insertions(+)
drivers/net/ethernet/qualcomm/emac/emac-phy.c +1 -0
@@ -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) {
drivers/net/ethernet/qualcomm/emac/emac.c +4 -0
@@ -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);
Signature · 1 line
2.7.3
Re: [PATCH net v2 5/5] net: qcom/emac: fix of_node and phydev leaks
Quoted 8 lines · Johan Hovold
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_nodereference taken byof_parse_phandle()in the same path.Fixes b9b17debc69d ("net: emac: emac gigabit ethernet controller driver")Signed-off-by Johan Hovold<[email protected]>
When I first wrote this code, I had a lot of trouble getting the PHY to re-probe when the driver was unloaded and reloaded, and it was because of some odd problems with get/put of of_nodes.
Since I know that you didn't test this driver on real hardware, I have to test these patches myself before I can ACK them.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Re: [PATCH net v2 5/5] net: qcom/emac: fix of_node and phydev leaks
In reply to Johan HovoldReview
Quoted 2 lines · Johan Hovold
(quoted diff) +2
-0+ if (!has_acpi_companion(&pdev->dev)) + put_device(&adpt->phydev->mdio.dev);
I was wondering if, instead of calling put_device() only on non-ACPI systems, would it be better if on an ACPI system I called get_device() manually? That is, some thing like this:
int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) {
...
if (has_acpi_companion(&pdev->dev)) {
...
get_device(&mii_bus->dev);
} else {...
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH net v2 5/5] net: qcom/emac: fix of_node and phydev leaks
Quoted 8 lines · Timur Tabi
Review
Quoted 2 lines · Johan Hovold
(quoted diff) +2
-0+ if (!has_acpi_companion(&pdev->dev)) + put_device(&adpt->phydev->mdio.dev);I was wondering if, instead of calling
put_device()only on non-ACPI systems, would it be better if on an ACPI system I calledget_device()manually? That is, some thing like this:
Quoted 8 lines
int
emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt){
...if (has_acpi_companion(&pdev->dev)) { ... get_device(&mii_bus->dev); } else {...
Yeah, that's better.
Thanks,
Johan
David Miller
maintainerFrom: Johan Hovold <[email protected]>
Date: Thu, 24 Nov 2016 19:21:26 +0100
Quoted 7 lines
This series fixes a number of phydev reference leaks (and one
of_nodeleak) due to failure to put the reference taken byof_phy_find_device().Note that I did not try to fix
drivers/net/phy/xilinx_gmii2rgmii.cwhich still leaks a reference.Against net but should apply just as fine to net-next.
...
Quoted 4 lines
v2:
- useput_device()instead ofphy_dev_free()to put the references taken in net/dsa (patch 1/4).
- add four new patches fixing similar leaks
Series applied, thanks.
Quoted 1 line · David Miller
Series applied, thanks.
I was really hoping you'd give me the chance to test the patches before applying them.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
David Miller
maintainerFrom: Timur Tabi <[email protected]>
Date: Sun, 27 Nov 2016 20:11:17 -0600
Quoted 5 lines
Quoted 1 line · David Miller
Series applied, thanks.
I was really hoping you'd give me the chance to test the patches before applying them.
Sorry, if anything is broken I will happily revert if it isn't fixed promptly.