From: Wang Ming <machel@vivo.com>
To: Sunil Goutham <sgoutham@marvell.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Daney <david.daney@cavium.com>,
linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Wang Ming <machel@vivo.com>
Subject: [PATCH net v3] net: thunder: bgx: Fix resource leaks in device_for_each_child_node() loops
Date: Fri, 14 Jul 2023 17:59:59 +0800 [thread overview]
Message-ID: <20230714100010.12035-1-machel@vivo.com> (raw)
The device_for_each_child_node() loop in bgx_init_of_phy()
function should have fwnode_handle_put() before break which could
avoid resource leaks. This patch could fix this bug.
Fixes: eee326fd8334 ("net: thunderx: bgx: Use standard firmware node infrastructure.")
Signed-off-by: Wang Ming <machel@vivo.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index a317feb8decb..f8a8b2ab72aa 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1469,6 +1469,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
struct fwnode_handle *fwn;
struct device_node *node = NULL;
u8 lmac = 0;
+ int err = 0;
device_for_each_child_node(&bgx->pdev->dev, fwn) {
struct phy_device *pd;
@@ -1479,7 +1480,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
*/
node = to_of_node(fwn);
if (!node)
- break;
+ goto out_handle_put;
of_get_mac_address(node, bgx->lmac[lmac].mac);
@@ -1501,10 +1502,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac++;
- if (lmac == bgx->max_lmac) {
- of_node_put(node);
- break;
- }
+ if (lmac == bgx->max_lmac)
+ goto out_node_put;
}
return 0;
@@ -1519,8 +1518,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
}
lmac--;
}
+ err = -EPROBE_DEFER;
+out_node_put:
of_node_put(node);
- return -EPROBE_DEFER;
+out_handle_put:
+ fwnode_handle_put(fwn);
+ return err;
}
#else
--
2.25.1
next reply other threads:[~2023-07-14 10:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 9:59 Wang Ming [this message]
[not found] ` <be87c113-f975-9607-1f9d-5db304e0b1b9@web.de>
2023-07-18 8:51 ` Paolo Abeni
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=20230714100010.12035-1-machel@vivo.com \
--to=machel@vivo.com \
--cc=davem@davemloft.net \
--cc=david.daney@cavium.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
--cc=pabeni@redhat.com \
--cc=sgoutham@marvell.com \
/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®