From: spinler@cesnet.cz
To: spinler@cesnet.cz
Cc: dev@dpdk.org
Subject: [PATCH 5/6] net/nfb: release allocated resources correctly
Date: Thu, 15 Jan 2026 15:01:33 +0100 [thread overview]
Message-ID: <20260115140134.235877-6-spinler@cesnet.cz> (raw)
In-Reply-To: <20260115140134.235877-1-spinler@cesnet.cz>
From: Martin Spinler <spinler@cesnet.cz>
Internal handles are initialized in eth_dev_init, so the cleanup
should be done in eth_dev_uninit.
Signed-off-by: Martin Spinler <spinler@cesnet.cz>
---
drivers/net/nfb/nfb_ethdev.c | 79 +++++++++++++++++++++---------------
1 file changed, 46 insertions(+), 33 deletions(-)
diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
index d73a5330ce..3bd9cab5fa 100644
--- a/drivers/net/nfb/nfb_ethdev.c
+++ b/drivers/net/nfb/nfb_ethdev.c
@@ -18,6 +18,9 @@
#include "nfb_rxmode.h"
#include "nfb.h"
+
+static int nfb_eth_dev_uninit(struct rte_eth_dev *dev);
+
/**
* Default MAC addr
*/
@@ -160,8 +163,6 @@ nfb_eth_dev_stop(struct rte_eth_dev *dev)
uint16_t nb_rx = dev->data->nb_rx_queues;
uint16_t nb_tx = dev->data->nb_tx_queues;
- dev->data->dev_started = 0;
-
for (i = 0; i < nb_tx; i++)
nfb_eth_tx_queue_stop(dev, i);
@@ -181,10 +182,9 @@ nfb_eth_dev_stop(struct rte_eth_dev *dev)
* 0 on success, a negative errno value otherwise.
*/
static int
-nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
+nfb_eth_dev_configure(struct rte_eth_dev *dev)
{
int ret;
- struct pmd_internals *internals = dev->process_private;
struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
@@ -193,12 +193,16 @@ nfb_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
&nfb_timestamp_rx_dynflag);
if (ret != 0) {
NFB_LOG(ERR, "Cannot register Rx timestamp field/flag %d", ret);
- nfb_close(internals->nfb);
- return -rte_errno;
+ ret = -ENOMEM;
+ goto err_ts_register;
}
}
return 0;
+
+err_ts_register:
+ nfb_eth_dev_uninit(dev);
+ return ret;
}
static uint32_t
@@ -262,32 +266,28 @@ nfb_eth_dev_info(struct rte_eth_dev *dev,
static int
nfb_eth_dev_close(struct rte_eth_dev *dev)
{
- struct pmd_internals *internals = dev->process_private;
uint16_t i;
uint16_t nb_rx = dev->data->nb_rx_queues;
uint16_t nb_tx = dev->data->nb_tx_queues;
- int ret;
- nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
- nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
-
- if (rte_eal_process_type() != RTE_PROC_PRIMARY)
- return 0;
-
- ret = nfb_eth_dev_stop(dev);
-
- for (i = 0; i < nb_rx; i++) {
- nfb_eth_rx_queue_release(dev, i);
- dev->data->rx_queues[i] = NULL;
- }
- dev->data->nb_rx_queues = 0;
- for (i = 0; i < nb_tx; i++) {
- nfb_eth_tx_queue_release(dev, i);
- dev->data->tx_queues[i] = NULL;
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ for (i = 0; i < nb_rx; i++) {
+ if (dev->data->rx_queues[i]) {
+ nfb_eth_rx_queue_release(dev, i);
+ dev->data->rx_queues[i] = NULL;
+ }
+ }
+ for (i = 0; i < nb_tx; i++) {
+ if (dev->data->tx_queues[i]) {
+ nfb_eth_tx_queue_release(dev, i);
+ dev->data->tx_queues[i] = NULL;
+ }
+ }
}
- dev->data->nb_tx_queues = 0;
- return ret;
+ nfb_eth_dev_uninit(dev);
+
+ return 0;
}
/**
@@ -509,6 +509,7 @@ static const struct eth_dev_ops ops = {
static int
nfb_eth_dev_init(struct rte_eth_dev *dev)
{
+ int ret;
uint32_t mac_count;
struct rte_eth_dev_data *data = dev->data;
struct pmd_internals *internals;
@@ -526,7 +527,8 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
sizeof(struct pmd_internals), RTE_CACHE_LINE_SIZE,
dev->device->numa_node);
if (internals == NULL) {
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_alloc_internals;
}
dev->process_private = internals;
@@ -544,8 +546,8 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
internals->nfb = nfb_open(nfb_dev);
if (internals->nfb == NULL) {
NFB_LOG(ERR, "nfb_open(): failed to open %s", nfb_dev);
- rte_free(internals);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_nfb_open;
}
priv->max_rx_queues = ndp_get_rx_queue_available_count(internals->nfb);
priv->max_tx_queues = ndp_get_tx_queue_available_count(internals->nfb);
@@ -577,9 +579,8 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
sizeof(struct rte_ether_addr) * mac_count, RTE_CACHE_LINE_SIZE);
if (data->mac_addrs == NULL) {
NFB_LOG(ERR, "Could not alloc space for MAC address");
- nfb_close(internals->nfb);
- rte_free(internals);
- return -EINVAL;
+ ret = -ENOMEM;
+ goto err_malloc_mac_addrs;
}
rte_eth_random_addr(eth_addr_init.addr_bytes);
@@ -601,6 +602,16 @@ nfb_eth_dev_init(struct rte_eth_dev *dev)
pci_addr->function);
return 0;
+
+err_malloc_mac_addrs:
+ nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
+ nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+ nfb_close(internals->nfb);
+
+err_nfb_open:
+ rte_free(internals);
+err_alloc_internals:
+ return ret;
}
/**
@@ -619,7 +630,9 @@ nfb_eth_dev_uninit(struct rte_eth_dev *dev)
struct rte_pci_addr *pci_addr = &pci_dev->addr;
struct pmd_internals *internals = dev->process_private;
- nfb_eth_dev_close(dev);
+ nfb_nc_rxmac_deinit(internals->rxmac, internals->max_rxmac);
+ nfb_nc_txmac_deinit(internals->txmac, internals->max_txmac);
+ nfb_close(internals->nfb);
rte_free(internals);
--
2.52.0
next prev parent reply other threads:[~2026-01-15 14:02 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 14:01 [PATCH 0/6] spinler
2026-01-15 14:01 ` [PATCH 1/6] net/nfb: use constant values for max Rx/Tx queues count spinler
2026-01-15 14:01 ` [PATCH 2/6] net/nfb: fix bad pointer access in queue stats spinler
2026-01-15 14:01 ` [PATCH 3/6] net/nfb: update timestamp calculation to meaningful value spinler
2026-01-15 14:01 ` [PATCH 4/6] net/nfb: use process private variable for internal data spinler
2026-01-15 14:01 ` spinler [this message]
2026-01-15 14:01 ` [PATCH 6/6] net/nfb: stop only started queues in fail path spinler
2026-01-15 14:40 ` [PATCH v2 0/6] net/nfb: code cleanup spinler
2026-01-15 14:40 ` [PATCH v2 1/6] net/nfb: use constant values for max Rx/Tx queues count spinler
2026-01-15 14:40 ` [PATCH v2 2/6] net/nfb: fix bad pointer access in queue stats spinler
2026-01-15 14:40 ` [PATCH v2 3/6] net/nfb: update timestamp calculation to meaningful value spinler
2026-01-15 14:40 ` [PATCH v2 4/6] net/nfb: use process private variable for internal data spinler
2026-01-15 14:40 ` [PATCH v2 5/6] net/nfb: release allocated resources correctly spinler
2026-01-15 14:40 ` [PATCH v2 6/6] net/nfb: stop only started queues in fail path spinler
2026-01-16 5:48 ` [PATCH v2 0/6] net/nfb: code cleanup Stephen Hemminger
2026-01-16 9:42 ` Martin Spinler
2026-01-16 17:39 ` Stephen Hemminger
2026-01-16 15:20 ` spinler
2026-01-16 15:20 ` [PATCH v3 1/6] net/nfb: use constant values for max Rx/Tx queues count spinler
2026-02-02 17:47 ` Stephen Hemminger
2026-02-02 18:58 ` Martin Špinler
2026-01-16 15:20 ` [PATCH v3 2/6] net/nfb: fix bad pointer access in queue stats spinler
2026-01-16 15:20 ` [PATCH v3 3/6] net/nfb: update timestamp calculation to meaningful value spinler
2026-01-16 15:20 ` [PATCH v3 4/6] net/nfb: use process private variable for internal data spinler
2026-01-20 0:13 ` Stephen Hemminger
2026-01-20 14:13 ` Martin Spinler
2026-01-20 16:11 ` Stephen Hemminger
2026-01-16 15:20 ` [PATCH v3 5/6] net/nfb: release allocated resources correctly spinler
2026-01-20 0:10 ` Stephen Hemminger
2026-01-20 14:14 ` Martin Spinler
2026-01-16 15:20 ` [PATCH v3 6/6] net/nfb: stop only started queues in fail path spinler
2026-01-20 0:09 ` Stephen Hemminger
2026-01-20 14:14 ` Martin Spinler
2026-01-16 15:22 ` [PATCH v3 0/6] net/nfb: code cleanup spinler
2026-01-21 4:57 ` Stephen Hemminger
2026-01-21 17:01 ` [PATCH v4 " spinler
2026-01-21 17:01 ` [PATCH v4 1/6] net/nfb: use constant values for max Rx/Tx queues count spinler
2026-01-21 17:01 ` [PATCH v4 2/6] net/nfb: fix bad pointer access in queue stats spinler
2026-01-21 17:01 ` [PATCH v4 3/6] net/nfb: update timestamp calculation to meaningful value spinler
2026-01-21 17:33 ` Stephen Hemminger
2026-01-27 8:12 ` Martin Spinler
2026-01-27 0:34 ` Stephen Hemminger
2026-01-27 8:16 ` Martin Spinler
2026-01-21 17:01 ` [PATCH v4 4/6] net/nfb: use process private variable for internal data spinler
2026-01-21 17:01 ` [PATCH v4 5/6] net/nfb: release allocated resources correctly spinler
2026-01-21 17:01 ` [PATCH v4 6/6] net/nfb: stop only started queues in fail path spinler
2026-01-21 17:35 ` [PATCH v4 0/6] net/nfb: code cleanup Stephen Hemminger
2026-02-02 19:33 ` [PATCH v5 " spinler
2026-02-02 19:33 ` [PATCH v5 1/6] net/nfb: use constant values for max Rx/Tx queues count spinler
2026-02-02 19:33 ` [PATCH v5 2/6] net/nfb: fix bad pointer access in queue stats spinler
2026-02-10 0:51 ` Stephen Hemminger
2026-02-02 19:33 ` [PATCH v5 3/6] net/nfb: update timestamp calculation to meaningful value spinler
2026-02-02 19:33 ` [PATCH v5 4/6] net/nfb: use process private variable for internal data spinler
2026-02-02 19:33 ` [PATCH v5 5/6] net/nfb: release allocated resources correctly spinler
2026-02-10 0:52 ` Stephen Hemminger
2026-02-02 19:33 ` [PATCH v5 6/6] net/nfb: stop only started queues in fail path spinler
2026-02-03 1:50 ` [PATCH v5 0/6] net/nfb: code cleanup Stephen Hemminger
2026-02-03 6:36 ` Martin Spinler
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=20260115140134.235877-6-spinler@cesnet.cz \
--to=spinler@cesnet.cz \
--cc=dev@dpdk.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