net: qcom/emac: grab a reference to the phydev on ACPI systems
Subsystems (3)
PATCH 1/1 net: qcom/emac: grab a reference to the phydev on ACPI systems
Commit 6ffe1c4cd0a7 ("net: qcom/emac: fix of_node and phydev leaks") fixed the problem with reference leaks on phydev, but the fix is device-tree specific. When the driver unloads, the reference is dropped only on DT systems.
Instead, it's cleaner if up grab an reference on ACPI systems. When the driver unloads, we can drop the reference without having to check whether we're on a DT system.
--- drivers/net/ethernet/qualcomm/emac/emac-phy.c | 6 ++++++ drivers/net/ethernet/qualcomm/emac/emac.c | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/qualcomm/emac/emac-phy.c +6 -0
@@ -201,6 +201,12 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)else adpt->phydev =mdiobus_get_phy (mii_bus, phy_addr); +/* of_phy_find_device() claims a reference to the phydev, +* so we do that here manually as well. When the driver +* unloads, it can unilaterally drops the reference +* without worrying about ACPI vs DT. +*/ +get_device (&adpt->phydev->mdio.dev); }else {struct device_node *phy_np;
drivers/net/ethernet/qualcomm/emac/emac.c +2 -4
@@ -729,8 +729,7 @@ 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); +put_device (&adpt->phydev->mdio.dev);mdiobus_unregister (adpt->mii_bus); err_undo_clocks:emac_clks_teardown (adpt);
@@ -750,8 +749,7 @@ static int emac_remove(struct platform_device *pdev)emac_clks_teardown (adpt); -if (!has_acpi_companion (&pdev->dev)) -put_device (&adpt->phydev->mdio.dev); +put_device (&adpt->phydev->mdio.dev);mdiobus_unregister (adpt->mii_bus);free_netdev (netdev);
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.
Quoted 20 lines · Timur Tabi
Commit
6ffe1c4cd0a7("net: qcom/emac: fixof_nodeand phydev leaks") fixed the problem with reference leaks on phydev, but the fix is device-tree specific. When the driver unloads, the reference is dropped only on DT systems.Instead, it's cleaner if up grab an reference on ACPI systems. When the driver unloads, we can drop the reference without having to check whether we're on a DT system.
Signed-off-by Timur Tabi <[email protected]>--- drivers/net/ethernet/qualcomm/emac/emac-phy.c | 6 ++++++ drivers/net/ethernet/qualcomm/emac/emac.c | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-)drivers/net/ethernet/qualcomm/emac/emac-phy.c +0
-0
drivers/net/ethernet/qualcomm/emac/emac-phy.c int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) · line 209
Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac-phy.c +6
-0@@ -201,6 +201,12 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)else adpt->phydev =mdiobus_get_phy (mii_bus, phy_addr); +/* of_phy_find_device() claims a reference to the phydev, +* so we do that here manually as well. When the driver +* unloads, it can unilaterally drops the reference +* without worrying about ACPI vs DT. +*/ +get_device (&adpt->phydev->mdio.dev);
But you cannot do this unconditionally as adpt->phydev can be NULL here.
Looks good to me otherwise.
Thanks,
Johan