2020-05-03 18:44:11

by Qiushi Wu

[permalink] [raw]
Subject: [PATCH v2] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()

From: Qiushi Wu <[email protected]>

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 <[email protected]>
---
drivers/net/ethernet/netronome/nfp/abm/main.c | 20 +++++++++----------
1 file changed, 10 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..a5152f11e2f5 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,15 @@ 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);
+
+generate_random_address:
+ eth_hw_addr_random(nn->dp.netdev);
+ return;
}

static int
--
2.17.1


2020-05-03 20:27:32

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH v2] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()

> … Thus add a call of the function
> “nfp_nsp_close” for the completion of the exception handling.

Thanks for your positive response.

I imagined that a small patch series would be more reasonable
than this direct change combination.



> +++ b/drivers/net/ethernet/netronome/nfp/abm/main.c

> ether_addr_copy(nn->dp.netdev->perm_addr, mac_addr);
> +
> +generate_random_address:
> + eth_hw_addr_random(nn->dp.netdev);
> + return;
> }


Unfortunately, you interpreted my update suggestion in a questionable way
at this source code place.
I guess that the following code variant can be considered instead.

ether_addr_copy(nn->dp.netdev->perm_addr, mac_addr);
+ return;
+
+generate_random_address:
+ eth_hw_addr_random(nn->dp.netdev);
}


Regards,
Markus