mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Navid Emamdoost <navid.emamdoost@gmail.com>
To: Nicolas Ferre <nicolas.ferre@microchip.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: emamd001@umn.edu, wu000273@umn.edu, kjlu@umn.edu,
	smccaman@umn.edu, Navid Emamdoost <navid.emamdoost@gmail.com>
Subject: [PATCH] net: macb: fix ref count leaking via pm_runtime_get_sync
Date: Sun, 14 Jun 2020 00:48:03 -0500	[thread overview]
Message-ID: <20200614054803.26757-1-navid.emamdoost@gmail.com> (raw)

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.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/net/ethernet/cadence/macb_main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index a0e8c5bbabc0..3646ab5a1e83 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -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 */
-- 
2.17.1


             reply	other threads:[~2020-06-14  5:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14  5:48 Navid Emamdoost [this message]
2020-06-15 20:42 ` David Miller
2020-06-14  8:56 Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200614054803.26757-1-navid.emamdoost@gmail.com \
    --to=navid.emamdoost@gmail.com \
    --cc=davem@davemloft.net \
    --cc=emamd001@umn.edu \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=smccaman@umn.edu \
    --cc=wu000273@umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®