Skip to content

Commit e9e9e79

Browse files
Renyong Wanshemminger
Renyong Wan
authored andcommitted
net/xsc: optimize release path
Optimized the code of release path to prevent potential resource leaks. Signed-off-by: Rong Qian <[email protected]> Signed-off-by: Renyong Wan <[email protected]>
1 parent b8d9eb7 commit e9e9e79

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

drivers/net/xsc/xsc_dev.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ int
150150
xsc_dev_close(struct xsc_dev *xdev, int repr_id)
151151
{
152152
xsc_dev_clear_pct(xdev, repr_id);
153-
return xdev->dev_ops->dev_close(xdev);
153+
154+
if (repr_id == xdev->num_repr_ports - 1)
155+
return xdev->dev_ops->dev_close(xdev);
156+
return 0;
154157
}
155158

156159
int

drivers/net/xsc/xsc_ethdev.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,21 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
860860
static int
861861
xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
862862
{
863+
int ret = 0;
864+
uint16_t port_id;
863865
struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
864866

865867
PMD_INIT_FUNC_TRACE();
868+
RTE_ETH_FOREACH_DEV_OF(port_id, eth_dev->device) {
869+
if (port_id != eth_dev->data->port_id)
870+
ret |= rte_eth_dev_close(port_id);
871+
}
866872

867-
xsc_dev_uninit(priv->xdev);
873+
ret |= xsc_ethdev_close(eth_dev);
874+
xsc_dev_pct_uninit();
875+
rte_free(priv->xdev);
868876

869-
return 0;
877+
return ret == 0 ? 0 : -EIO;
870878
}
871879

872880
static int

drivers/net/xsc/xsc_np.c

+1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ void
383383
xsc_dev_pct_uninit(void)
384384
{
385385
rte_free(xsc_pct_mgr.bmp_mem);
386+
xsc_pct_mgr.bmp_mem = NULL;
386387
}
387388

388389
int

drivers/net/xsc/xsc_vfio.c

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ xsc_vfio_dev_close(struct xsc_dev *xdev)
178178
struct xsc_vfio_priv *vfio_priv = (struct xsc_vfio_priv *)xdev->dev_priv;
179179

180180
xsc_vfio_mbox_destroy(vfio_priv->cmdq);
181+
rte_pci_unmap_device(xdev->pci_dev);
181182
rte_free(vfio_priv);
182183

183184
return 0;

0 commit comments

Comments
 (0)