Skip to contentSkip to conversation

net: macb: fix ref count leaking via pm_runtime_get_sync

PATCH In review Navid Emamdoost 2 participants 2 messages Jun 14, 2020 – Jun 15, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: macb: fix ref count leaking via pm_runtime_get_sync

in macb_mdio_write, macb_mdio_read, and at91ether_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count.
In case of failure, decrement the ref count before returning.

---
 drivers/net/ethernet/cadence/macb_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +10 -5
index a0e8c5bbabc0..3646ab5a1e83 100644
@@ -335,7 +335,7 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 
 	status = pm_runtime_get_sync(&bp->pdev->dev);
 	if (status < 0)
-		goto mdio_pm_exit;
+		goto mdio_pm_put;
 
 	status = macb_mdio_wait_for_idle(bp);
 	if (status < 0)
@@ -374,6 +374,7 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 
 mdio_read_exit:
 	pm_runtime_mark_last_busy(&bp->pdev->dev);
+mdio_pm_put:
 	pm_runtime_put_autosuspend(&bp->pdev->dev);
 mdio_pm_exit:
 	return status;
@@ -387,7 +388,7 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 
 	status = pm_runtime_get_sync(&bp->pdev->dev);
 	if (status < 0)
-		goto mdio_pm_exit;
+		goto mdio_pm_put;
 
 	status = macb_mdio_wait_for_idle(bp);
 	if (status < 0)
@@ -426,6 +427,7 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 
 mdio_write_exit:
 	pm_runtime_mark_last_busy(&bp->pdev->dev);
+mdio_pm_put:
 	pm_runtime_put_autosuspend(&bp->pdev->dev);
 mdio_pm_exit:
 	return status;
@@ -3817,7 +3819,7 @@ static int at91ether_open(struct net_device *dev)
 
 	ret = pm_runtime_get_sync(&lp->pdev->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	/* Clear internal statistics */
 	ctl = macb_readl(lp, NCR);
@@ -3827,7 +3829,7 @@ static int at91ether_open(struct net_device *dev)
 
 	ret = at91ether_start(dev);
 	if (ret)
-		return ret;
+		goto out;
 
 	/* Enable MAC interrupts */
 	macb_writel(lp, IER, MACB_BIT(RCOMP)	|
@@ -3840,11 +3842,14 @@ static int at91ether_open(struct net_device *dev)
 
 	ret = macb_phylink_connect(lp);
 	if (ret)
-		return ret;
+		goto out;
 
 	netif_start_queue(dev);
 
 	return 0;
+out:
+	pm_runtime_put(&lp->pdev->dev);
+	return ret;
 }
 
 /* Close the interface */
Signature · 1 line
2.17.1
maintainer
#1 lore raw

From: Navid Emamdoost <[email protected]>
Date: Sun, 14 Jun 2020 00:48:03 -0500

Quoted 6 lines

in macb_mdio_write, macb_mdio_read, and at91ether_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count.
In case of failure, decrement the ref count before returning.

This does not apply to the net tree.