diff mbox

[net,v2,5/5] net: qcom/emac: fix of_node and phydev leaks

Message ID 1480011691-13278-6-git-send-email-johan@kernel.org
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Johan Hovold Nov. 24, 2016, 6:21 p.m. UTC
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>
---
 drivers/net/ethernet/qualcomm/emac/emac-phy.c | 1 +
 drivers/net/ethernet/qualcomm/emac/emac.c     | 4 ++++
 2 files changed, 5 insertions(+)

Comments

Timur Tabi Nov. 24, 2016, 6:55 p.m. UTC | #1
Johan Hovold wrote:
> 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>

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.
Timur Tabi Jan. 9, 2017, 7:49 p.m. UTC | #2
On 11/24/2016 12:21 PM, Johan Hovold wrote:
> +	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 {
...
Johan Hovold Jan. 10, 2017, 8:43 a.m. UTC | #3
On Mon, Jan 09, 2017 at 01:49:53PM -0600, Timur Tabi wrote:
> On 11/24/2016 12:21 PM, Johan Hovold wrote:
> > +	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 {
> ...

Yeah, that's better.

Thanks,
Johan
diff mbox

Patch

diff --git a/drivers/net/ethernet/qualcomm/emac/emac-phy.c b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
index da4e90db4d98..99a14df28b96 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-phy.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
@@ -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) {
diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c
index 4fede4b86538..57b35aeac51a 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -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);