From: ddaney.cavm@gmail.com (David Daney)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] net: thunderx: Don't leak phy device references on -EPROBE_DEFER condition.
Date: Mon, 14 Mar 2016 17:30:39 -0700 [thread overview]
Message-ID: <1458001839-15993-4-git-send-email-ddaney.cavm@gmail.com> (raw)
In-Reply-To: <1458001839-15993-1-git-send-email-ddaney.cavm@gmail.com>
From: David Daney <david.daney@cavium.com>
It is possible, although unlikely, that probing will find the
phy_device for the first LMAC of a thunder BGX device, but then need
to fail with -EPROBE_DEFER on a subsequent LMAC. In this case, we
need to call put_device() on each of the phy_devices that were
obtained, but will be unused due to returning -EPROBE_DEFER.
Also, since we can break out of the probing loop early, we need to
explicitly call of_node_put() outside of the loop.
Signed-off-by: David Daney <david.daney@cavium.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 26 +++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index feed231..9679515 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -974,17 +974,18 @@ static int bgx_init_acpi_phy(struct bgx *bgx)
static int bgx_init_of_phy(struct bgx *bgx)
{
struct fwnode_handle *fwn;
+ struct device_node *node = NULL;
u8 lmac = 0;
- const char *mac;
device_for_each_child_node(&bgx->pdev->dev, fwn) {
struct phy_device *pd;
struct device_node *phy_np;
- struct device_node *node = to_of_node(fwn);
+ const char *mac;
/* Should always be an OF node. But if it is not, we
* cannot handle it, so exit the loop.
*/
+ node = to_of_node(fwn);
if (!node)
break;
@@ -1005,17 +1006,30 @@ static int bgx_init_of_phy(struct bgx *bgx)
/* Wait until the phy drivers are available */
pd = of_phy_find_device(phy_np);
if (!pd)
- return -EPROBE_DEFER;
+ goto defer;
bgx->lmac[lmac].phydev = pd;
}
lmac++;
- if (lmac == MAX_LMAC_PER_BGX) {
- of_node_put(node);
+ if (lmac == MAX_LMAC_PER_BGX)
break;
- }
}
+ of_node_put(node);
return 0;
+
+defer:
+ /* We are bailing out, try not to leak device reference counts
+ * for phy devices we may have already found.
+ */
+ while (lmac) {
+ if (bgx->lmac[lmac].phydev) {
+ put_device(&bgx->lmac[lmac].phydev->mdio.dev);
+ bgx->lmac[lmac].phydev = NULL;
+ }
+ lmac--;
+ }
+ of_node_put(node);
+ return -EPROBE_DEFER;
}
#else
--
1.7.11.7
prev parent reply other threads:[~2016-03-15 0:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-15 0:30 [PATCH 0/3] net/phy: Fixes for Cavium Thunder MDIO code David Daney
2016-03-15 0:30 ` [PATCH 1/3] phy: mdio-cavium: Add missing MODULE_* annotations David Daney
2016-03-15 0:30 ` [PATCH 2/3] net: cavium: For Kconfig THUNDER_NIC_BGX, select MDIO_THUNDER David Daney
2016-03-15 0:30 ` David Daney [this message]
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=1458001839-15993-4-git-send-email-ddaney.cavm@gmail.com \
--to=ddaney.cavm@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).