Skip to contentSkip to conversation

net: macb: Fix runtime PM refcounting

PATCH Applied Andy Shevchenko 3 participants 5 messages Apr 27, 2020 – May 1, 2020

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

PATCH 1/1 net: macb: Fix runtime PM refcounting

The commit e6a41c23df0d, while trying to fix an issue,

("net: macb: ensure interface is not suspended on at91rm9200")

introduced a refcounting regression, because in error case refcounter must be balanced. Fix it by calling pm_runtime_put_noidle() in error case.

While here, fix the same mistake in other couple of places.

Fixes e6a41c23df0d ("net: macb: ensure interface is not suspended on at91rm9200")
Cc Alexandre Belloni <[email protected]>
Cc Claudiu Beznea <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +9 -3
index a0e8c5bbabc01..f739d16d29b1d 100644
@@ -334,8 +334,10 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 	int status;
 
 	status = pm_runtime_get_sync(&bp->pdev->dev);
-	if (status < 0)
+	if (status < 0) {
+		pm_runtime_put_noidle(&bp->pdev->dev);
 		goto mdio_pm_exit;
+	}
 
 	status = macb_mdio_wait_for_idle(bp);
 	if (status < 0)
@@ -386,8 +388,10 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	int status;
 
 	status = pm_runtime_get_sync(&bp->pdev->dev);
-	if (status < 0)
+	if (status < 0) {
+		pm_runtime_put_noidle(&bp->pdev->dev);
 		goto mdio_pm_exit;
+	}
 
 	status = macb_mdio_wait_for_idle(bp);
 	if (status < 0)
@@ -3816,8 +3820,10 @@ static int at91ether_open(struct net_device *dev)
 	int ret;
 
 	ret = pm_runtime_get_sync(&lp->pdev->dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(&lp->pdev->dev);
 		return ret;
+	}
 
 	/* Clear internal statistics */
 	ctl = macb_readl(lp, NCR);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 24 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

The commit e6a41c23df0d, while trying to fix an issue,

("net: macb: ensure interface is not suspended on at91rm9200")

introduced a refcounting regression, because in error case refcounter must be balanced. Fix it by calling pm_runtime_put_noidle() in error case.

While here, fix the same mistake in other couple of places.

Fixes e6a41c23df0d ("net: macb: ensure interface is not suspended on at91rm9200")
Cc Alexandre Belloni <[email protected]>
Cc Claudiu Beznea <[email protected]>
---
 drivers/net/ethernet/cadence/macb_main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +0 -0
index a0e8c5bbabc01..f739d16d29b1d 100644

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) · line 338

Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +2 -1
@@ -334,8 +334,10 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
        int status;
 
        status = pm_runtime_get_sync(&bp->pdev->dev);
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

pm_runtime_get_sync() calls __pm_runtime_resume(dev, RPM_GET_PUT), increment refcounter and resume the device calling rpm_resume().

pm_runtime_put_noidle() just decrement the refcounter. The proper way, should be calling suspend again if the operation fails as pm_runtime_put_autosuspend() does. So, what the code under mdio_pm_exit label does should be enough.

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum, · line 392

Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c +3 -1
                goto mdio_pm_exit;
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -386,8 +388,10 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
        int status;
 
        status = pm_runtime_get_sync(&bp->pdev->dev);
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

Ditto.

drivers/net/ethernet/cadence/macb_main.c static int at91ether_open(struct net_device *dev) · line 3824

Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c +3 -1
                goto mdio_pm_exit;
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -3816,8 +3820,10 @@ static int at91ether_open(struct net_device *dev)
        int ret;
 
        ret = pm_runtime_get_sync(&lp->pdev->dev);
-       if (ret < 0)
+       if (ret < 0) {
+               pm_runtime_put_noidle(&lp->pdev->dev);

The proper way should be calling pm_runtime_put_sync() not only for this returning path but for all of them in this function.

Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
                return ret;
+       }
 
        /* Clear internal statistics */
        ctl = macb_readl(lp, NCR);
--

2.26.2

#2 lore raw
Quoted 13 lines · On Thu, Apr 30, 2020 at 07:59:41AM +0000, [email protected] wrote:
Quoted 10 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

The commit e6a41c23df0d, while trying to fix an issue,

("net: macb: ensure interface is not suspended on at91rm9200")

introduced a refcounting regression, because in error case refcounter must be balanced. Fix it by calling pm_runtime_put_noidle() in error case.

While here, fix the same mistake in other couple of places.

...

Quoted 7 lines

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) · line 338

Quoted 4 lines
        status = pm_runtime_get_sync(&bp->pdev->dev);
drivers/net/ethernet/cadence/macb_main.c +2 -1
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

pm_runtime_get_sync() calls __pm_runtime_resume(dev, RPM_GET_PUT), increment refcounter and resume the device calling rpm_resume().

Read the code further than the header file, please.

Quoted 1 line

pm_runtime_put_noidle() just decrement the refcounter.

which is exactly what has to be done on error path.

Quoted 4 lines

The proper way,
should be calling suspend again if the operation fails as pm_runtime_put_autosuspend() does. So, what the code under mdio_pm_exit label does should be enough.

Huh? It returns an error without rebalancing refcounter.

Yeah, one more time an evidence that people do not get runtime PM properly.

Quoted 8 lines
Quoted 8 lines
                goto mdio_pm_exit;
drivers/net/ethernet/cadence/macb_main.c +1 -0
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -386,8 +388,10 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
        int status;
 
Quoted 6 lines

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) · line 338

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +2 -1
        status = pm_runtime_get_sync(&bp->pdev->dev);
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

Ditto.

Ditto.

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +1 -0
                goto mdio_pm_exit;
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -3816,8 +3820,10 @@ static int at91ether_open(struct net_device *dev)
        int ret;
 
Quoted 7 lines

drivers/net/ethernet/cadence/macb_main.c static int at91ether_open(struct net_device *dev) · line 3824

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +2 -1
        ret = pm_runtime_get_sync(&lp->pdev->dev);
-       if (ret < 0)
+       if (ret < 0) {
+               pm_runtime_put_noidle(&lp->pdev->dev);

The proper way should be calling pm_runtime_put_sync() not only for this returning path but for all of them in this function.

Of course not.

Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
                return ret;
+       }
 
        /* Clear internal statistics */
        ctl = macb_readl(lp, NCR);
--

2.26.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 31 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 13 lines · On Thu, Apr 30, 2020 at 07:59:41AM +0000, [email protected] wrote:
Quoted 10 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

The commit e6a41c23df0d, while trying to fix an issue,

("net: macb: ensure interface is not suspended on at91rm9200")

introduced a refcounting regression, because in error case refcounter must be balanced. Fix it by calling pm_runtime_put_noidle() in error case.

While here, fix the same mistake in other couple of places.

...

Quoted 7 lines

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) · line 338

Quoted 4 lines
        status = pm_runtime_get_sync(&bp->pdev->dev);
drivers/net/ethernet/cadence/macb_main.c +2 -1
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

pm_runtime_get_sync() calls __pm_runtime_resume(dev, RPM_GET_PUT), increment refcounter and resume the device calling rpm_resume().

Read the code further than the header file, please.

Quoted 1 line

pm_runtime_put_noidle() just decrement the refcounter.

Quoted 8 lines

which is exactly what has to be done on error path.

Quoted 4 lines

The proper way,
should be calling suspend again if the operation fails as pm_runtime_put_autosuspend() does. So, what the code under mdio_pm_exit label does should be enough.

Huh? It returns an error without rebalancing refcounter.

Yep, my mistake. Your code is good.

Quoted 52 lines

Yeah, one more time an evidence that people do not get runtime PM properly.>

Quoted 8 lines
Quoted 8 lines
                goto mdio_pm_exit;
drivers/net/ethernet/cadence/macb_main.c +1 -0
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -386,8 +388,10 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
        int status;
 
Quoted 6 lines

drivers/net/ethernet/cadence/macb_main.c static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum) · line 338

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +2 -1
        status = pm_runtime_get_sync(&bp->pdev->dev);
-       if (status < 0)
+       if (status < 0) {
+               pm_runtime_put_noidle(&bp->pdev->dev);

Ditto.

Ditto.

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +1 -0
                goto mdio_pm_exit;
+       }
 
        status = macb_mdio_wait_for_idle(bp);
        if (status < 0)
@@ -3816,8 +3820,10 @@ static int at91ether_open(struct net_device *dev)
        int ret;
 
Quoted 7 lines

drivers/net/ethernet/cadence/macb_main.c static int at91ether_open(struct net_device *dev) · line 3824

Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +2 -1
        ret = pm_runtime_get_sync(&lp->pdev->dev);
-       if (ret < 0)
+       if (ret < 0) {
+               pm_runtime_put_noidle(&lp->pdev->dev);

The proper way should be calling pm_runtime_put_sync() not only for this returning path but for all of them in this function.

Of course not.

Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +1 -1
                return ret;
+       }
 
        /* Clear internal statistics */
        ctl = macb_readl(lp, NCR);
--

2.26.2

--
With Best Regards,
Andy Shevchenko

maintainer Applied
#4 lore raw
In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>
Date: Mon, 27 Apr 2020 13:51:20 +0300

Quoted 7 lines

The commit e6a41c23df0d, while trying to fix an issue,

("net: macb: ensure interface is not suspended on at91rm9200")

introduced a refcounting regression, because in error case refcounter must be balanced. Fix it by calling pm_runtime_put_noidle() in error case.

Quoted 6 lines

While here, fix the same mistake in other couple of places.

Fixes e6a41c23df0d ("net: macb: ensure interface is not suspended on at91rm9200")
Cc Alexandre Belloni <[email protected]>
Cc Claudiu Beznea <[email protected]>

Applied, thank you.