From: wu000273@umn.edu
To: kuba@kernel.org
Cc: davem@davemloft.net, Markus.Elfring@web.de,
oss-drivers@netronome.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, kjlu@umn.edu, wu000273@umn.edu
Subject: [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
Date: Sun, 3 May 2020 15:49:32 -0500 [thread overview]
Message-ID: <20200503204932.11167-1-wu000273@umn.edu> (raw)
From: Qiushi Wu <wu000273@umn.edu>
In function nfp_abm_vnic_set_mac, pointer nsp is allocated by nfp_nsp_open.
But when nfp_nsp_has_hwinfo_lookup fail, the pointer is not released,
which can lead to a memory leak bug. Thus add a call of the function
“nfp_nsp_close” for the completion of the exception handling.
Fixes: f6e71efdf9fb1 ("nfp: abm: look up MAC addresses via management FW")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
drivers/net/ethernet/netronome/nfp/abm/main.c | 21 ++++++++++---------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/netronome/nfp/abm/main.c b/drivers/net/ethernet/netronome/nfp/abm/main.c
index 9183b3e85d21..f196789f62fe 100644
--- a/drivers/net/ethernet/netronome/nfp/abm/main.c
+++ b/drivers/net/ethernet/netronome/nfp/abm/main.c
@@ -265,8 +265,7 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
if (id > pf->eth_tbl->count) {
nfp_warn(pf->cpp, "No entry for persistent MAC address\n");
- eth_hw_addr_random(nn->dp.netdev);
- return;
+ goto generate_random_address;
}
snprintf(hwinfo, sizeof(hwinfo), "eth%u.mac.pf%u",
@@ -276,14 +275,13 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
if (IS_ERR(nsp)) {
nfp_warn(pf->cpp, "Failed to access the NSP for persistent MAC address: %ld\n",
PTR_ERR(nsp));
- eth_hw_addr_random(nn->dp.netdev);
- return;
+ goto generate_random_address;
}
if (!nfp_nsp_has_hwinfo_lookup(nsp)) {
nfp_warn(pf->cpp, "NSP doesn't support PF MAC generation\n");
- eth_hw_addr_random(nn->dp.netdev);
- return;
+ nfp_nsp_close(nsp);
+ goto generate_random_address;
}
err = nfp_nsp_hwinfo_lookup(nsp, hwinfo, sizeof(hwinfo));
@@ -291,8 +289,7 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
if (err) {
nfp_warn(pf->cpp, "Reading persistent MAC address failed: %d\n",
err);
- eth_hw_addr_random(nn->dp.netdev);
- return;
+ goto generate_random_address;
}
if (sscanf(hwinfo, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
@@ -300,12 +297,16 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
&mac_addr[3], &mac_addr[4], &mac_addr[5]) != 6) {
nfp_warn(pf->cpp, "Can't parse persistent MAC address (%s)\n",
hwinfo);
- eth_hw_addr_random(nn->dp.netdev);
- return;
+ goto generate_random_address;
}
ether_addr_copy(nn->dp.netdev->dev_addr, mac_addr);
ether_addr_copy(nn->dp.netdev->perm_addr, mac_addr);
+ return;
+
+generate_random_address:
+ eth_hw_addr_random(nn->dp.netdev);
+ return;
}
static int
--
2.17.1
next reply other threads:[~2020-05-03 20:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-03 20:49 wu000273 [this message]
2020-05-04 6:01 ` [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac() Markus Elfring
2020-05-04 7:34 ` Markus Elfring
2020-05-04 17:03 ` Jakub Kicinski
[not found] ` <CAMV6ehFC=efyD81rtNRcWW9gbiD4t6z4G2TkLk7WqLS+Qg9X-Q@mail.gmail.com>
2020-05-04 20:13 ` [v3] " Markus Elfring
[not found] ` <CAMV6ehE=GXooHwG1TQ-LZqpepceAudX=P63o139UgKG7TMRxwQ@mail.gmail.com>
2020-05-05 5:48 ` Markus Elfring
[not found] ` <CAMV6ehEP-X+5bXj6VXMpZCPkr6YZWsB0Z_sTBxFxNpwa6D0Z0Q@mail.gmail.com>
2020-05-05 8:26 ` Markus Elfring
[not found] ` <CAMV6ehE9YRxakbP9ahXkiZEPut8E3qYsN0cxiLqCWasfvLAWFw@mail.gmail.com>
2020-05-05 20:17 ` Markus Elfring
[not found] ` <CAMV6ehFCcSZtqpxonfbp6i_v5zzmnLJ9Gncx=5Y36R35wqTtDw@mail.gmail.com>
2020-05-06 6:12 ` Markus Elfring
[not found] ` <CAK8KejrEuumVxdbBmuHbhjXQa7KH_jP-XLmAHjp1+AC7DUa9WQ@mail.gmail.com>
2020-05-07 7:23 ` [v3] nfp: abm: University research groups? 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=20200503204932.11167-1-wu000273@umn.edu \
--to=wu000273@umn.edu \
--cc=Markus.Elfring@web.de \
--cc=davem@davemloft.net \
--cc=kjlu@umn.edu \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.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;
as well as URLs for NNTP newsgroup(s).