From: "Renyong Wan" <wanry@yunsilicon.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <stephen@networkplumber.org>,
<qianr@yunsilicon.com>, <nana@yunsilicon.com>,
<zhangxx@yunsilicon.com>, <xudw@yunsilicon.com>,
<jacky@yunsilicon.com>, <weihg@yunsilicon.com>,
<zhenghy@yunsilicon.com>
Subject: [PATCH 2/2] net/xsc: optimize release path
Date: Fri, 18 Apr 2025 18:34:38 +0800 [thread overview]
Message-ID: <20250418103437.2489377-3-wanry@yunsilicon.com> (raw)
In-Reply-To: <20250418103434.2489377-1-wanry@yunsilicon.com>
Optimized the code of release path to prevent potential resource leaks.
Signed-off-by: Rong Qian <qianr@yunsilicon.com>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
drivers/net/xsc/xsc_dev.c | 5 ++++-
drivers/net/xsc/xsc_ethdev.c | 12 ++++++++++--
drivers/net/xsc/xsc_np.c | 1 +
drivers/net/xsc/xsc_vfio.c | 1 +
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 1e3dd493f9..fc9f1cddfc 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -150,7 +150,10 @@ int
xsc_dev_close(struct xsc_dev *xdev, int repr_id)
{
xsc_dev_clear_pct(xdev, repr_id);
- return xdev->dev_ops->dev_close(xdev);
+
+ if (repr_id == xdev->num_repr_ports - 1)
+ return xdev->dev_ops->dev_close(xdev);
+ return 0;
}
int
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 28af9c5d15..3830c18c03 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -860,13 +860,21 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
static int
xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
{
+ int ret = 0;
+ uint16_t port_id;
struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
PMD_INIT_FUNC_TRACE();
+ RTE_ETH_FOREACH_DEV_OF(port_id, eth_dev->device) {
+ if (port_id != eth_dev->data->port_id)
+ ret |= rte_eth_dev_close(port_id);
+ }
- xsc_dev_uninit(priv->xdev);
+ ret |= xsc_ethdev_close(eth_dev);
+ xsc_dev_pct_uninit();
+ rte_free(priv->xdev);
- return 0;
+ return ret == 0 ? 0 : -EIO;
}
static int
diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c
index f96797b7a4..543e6dba95 100644
--- a/drivers/net/xsc/xsc_np.c
+++ b/drivers/net/xsc/xsc_np.c
@@ -383,6 +383,7 @@ void
xsc_dev_pct_uninit(void)
{
rte_free(xsc_pct_mgr.bmp_mem);
+ xsc_pct_mgr.bmp_mem = NULL;
}
int
diff --git a/drivers/net/xsc/xsc_vfio.c b/drivers/net/xsc/xsc_vfio.c
index 8330483523..422d30efb9 100644
--- a/drivers/net/xsc/xsc_vfio.c
+++ b/drivers/net/xsc/xsc_vfio.c
@@ -178,6 +178,7 @@ xsc_vfio_dev_close(struct xsc_dev *xdev)
struct xsc_vfio_priv *vfio_priv = (struct xsc_vfio_priv *)xdev->dev_priv;
xsc_vfio_mbox_destroy(vfio_priv->cmdq);
+ rte_pci_unmap_device(xdev->pci_dev);
rte_free(vfio_priv);
return 0;
--
2.25.1
prev parent reply other threads:[~2025-04-18 10:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 10:34 [PATCH 0/2] Optimize the code to void resource leaks Renyong Wan
2025-04-18 10:34 ` [PATCH 1/2] net/xsc: fix " Renyong Wan
2025-04-18 10:34 ` Renyong Wan [this message]
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=20250418103437.2489377-3-wanry@yunsilicon.com \
--to=wanry@yunsilicon.com \
--cc=dev@dpdk.org \
--cc=jacky@yunsilicon.com \
--cc=nana@yunsilicon.com \
--cc=qianr@yunsilicon.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
--cc=weihg@yunsilicon.com \
--cc=xudw@yunsilicon.com \
--cc=zhangxx@yunsilicon.com \
--cc=zhenghy@yunsilicon.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).