The failed label in eth_hn_dev_init() does not free hv->primary or close
hv->channels[0], leaking both resources on any init failure after they
are allocated.
Additionally, the early return when hv->primary allocation fails leaks
hv->channels[0]. Change it to goto failed.
Add rte_free(hv->primary) and rte_vmbus_chan_close(hv->channels[0]) to
the failed label to properly clean up on all error paths.
Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")
Cc: [email protected]
Signed-off-by: Long Li <[email protected]>
---
v3: New patch.
---
drivers/net/netvsc/hn_ethdev.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 9f61f3a1a5..19721b4829 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -1376,8 +1376,10 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
hv->primary = hn_rx_queue_alloc(hv, 0,
eth_dev->device->numa_node);
- if (!hv->primary)
- return -ENOMEM;
+ if (!hv->primary) {
+ err = -ENOMEM;
+ goto failed;
+ }
err = hn_attach(hv, RTE_ETHER_MTU);
if (err)
@@ -1403,8 +1405,10 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
max_chan = rte_vmbus_max_channels(vmbus);
PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
- if (max_chan <= 0)
+ if (max_chan <= 0) {
+ err = max_chan ? max_chan : -ENODEV;
goto failed;
+ }
if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
rxr_cnt = 1;
@@ -1425,6 +1429,8 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
hn_chim_uninit(eth_dev);
hn_detach(hv);
+ rte_free(hv->primary);
+ rte_vmbus_chan_close(hv->channels[0]);
return err;
}
--
2.43.0