* [PATCH v2 2/3] net/xsc: fix leak and missing null check
2026-11-16 6:58 [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
@ 2026-11-16 6:58 ` Renyong Wan
2026-11-16 6:58 ` [PATCH v2 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Renyong Wan @ 2026-11-16 6:58 UTC (permalink / raw)
To: dev; +Cc: stephen, nana, qianr, zhangxx, xudw, stable
xsc_dev_init() leaks the structure when the dev_ops lookup fails. Free
it there: xsc_dev_uninit() cannot be used, as xsc_dev_close()
dereferences xdev->dev_ops.
xsc_ethdev_tx_queue_setup() misses the NULL check on the
rte_malloc_socket() result. Return -ENOMEM, as the Rx path does.
Fixes: fb7d4f7ae39a ("net/xsc: add device initialization")
Fixes: 488262986eee ("net/xsc: support Rx and Tx queue setup")
Cc: stable@dpdk.org
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
drivers/net/xsc/xsc_dev.c | 1 +
drivers/net/xsc/xsc_ethdev.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 6bd12510..ae0dca16 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -366,6 +366,7 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **xdev)
d->dev_ops = xsc_dev_ops_get(pci_dev->kdrv);
if (d->dev_ops == NULL) {
PMD_DRV_LOG(ERR, "Could not get dev_ops, kdrv=%d", pci_dev->kdrv);
+ rte_free(d);
return -ENODEV;
}
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 20d6f58f..a5c3e4a6 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -545,6 +545,12 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
txq = rte_malloc_socket(NULL, sizeof(*txq) + desc_n * sizeof(struct rte_mbuf *),
RTE_CACHE_LINE_SIZE, socket);
+ if (txq == NULL) {
+ PMD_DRV_LOG(ERR, "Port %u create txq idx %d failure",
+ dev->data->port_id, idx);
+ rte_errno = ENOMEM;
+ return -rte_errno;
+ }
txq->offloads = conf->offloads | dev->data->dev_conf.txmode.offloads;
txq->priv = priv;
txq->socket = socket;
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/3] net/xsc: rename jumbo buffer fields
2026-11-16 6:58 [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-16 6:58 ` [PATCH v2 2/3] net/xsc: fix leak and missing null check Renyong Wan
@ 2026-11-16 6:58 ` Renyong Wan
2026-11-16 6:58 ` [PATCH v2 1/3] net/xsc: fix jumbo buffer allocation and leak Renyong Wan
2026-11-16 18:46 ` [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger
3 siblings, 0 replies; 6+ messages in thread
From: Renyong Wan @ 2026-11-16 6:58 UTC (permalink / raw)
To: dev; +Cc: stephen, nana, qianr, zhangxx, xudw
The names are the other way round: jumbo_buffer_pa holds the virtual
address and jumbo_buffer_va holds the IOVA, which is why the bug went
unnoticed.
Rename them to jumbo_buf and jumbo_iova with matching types, which also
removes the casts.
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
drivers/net/xsc/xsc_dev.c | 2 +-
drivers/net/xsc/xsc_dev.h | 4 ++--
drivers/net/xsc/xsc_rx.c | 22 +++++++++++-----------
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index ae0dca16..c666a47e 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -345,7 +345,7 @@ xsc_dev_uninit(struct xsc_dev *xdev)
PMD_INIT_FUNC_TRACE();
xsc_dev_pct_uninit(xdev);
xsc_dev_close(xdev, XSC_DEV_REPR_ID_INVALID);
- rte_free(xdev->jumbo_buffer_pa);
+ rte_free(xdev->jumbo_buf);
rte_free(xdev);
}
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index d4a7d90b..3473333c 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -189,8 +189,8 @@ struct xsc_dev {
void *dev_priv;
char name[PCI_PRI_STR_SIZE];
void *bar_addr;
- void *jumbo_buffer_pa;
- void *jumbo_buffer_va;
+ void *jumbo_buf;
+ rte_iova_t jumbo_iova;
uint64_t bar_len;
int ctrl_fd;
rte_intr_callback_fn intr_cb;
diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c
index 5baeedf1..3435ff67 100644
--- a/drivers/net/xsc/xsc_rx.c
+++ b/drivers/net/xsc/xsc_rx.c
@@ -206,27 +206,27 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
uint32_t log2ds = rte_log2_u32(rx_ds_num);
uintptr_t addr;
struct rte_mbuf *mbuf;
- void *jumbo_buffer_pa = xdev->jumbo_buffer_pa;
- void *jumbo_buffer_va = xdev->jumbo_buffer_va;
+ void *jumbo_buf = xdev->jumbo_buf;
+ rte_iova_t jumbo_iova = xdev->jumbo_iova;
volatile struct xsc_wqe_data_seg *seg;
volatile struct xsc_wqe_data_seg *seg_next;
- if ((rx_ds_num != 1) && (jumbo_buffer_va == NULL)) {
- jumbo_buffer_pa = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
- if (jumbo_buffer_pa == NULL) {
+ if ((rx_ds_num != 1) && (jumbo_buf == NULL)) {
+ jumbo_buf = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
+ if (jumbo_buf == NULL) {
PMD_DRV_LOG(ERR, "Failed to malloc jumbo_buffer");
return -ENOMEM;
}
- jumbo_buffer_va = (void *)rte_malloc_virt2iova(jumbo_buffer_pa);
- if ((rte_iova_t)jumbo_buffer_va == RTE_BAD_IOVA) {
+ jumbo_iova = rte_malloc_virt2iova(jumbo_buf);
+ if (jumbo_iova == RTE_BAD_IOVA) {
PMD_DRV_LOG(ERR, "Failed to get IOVA of jumbo_buffer");
- rte_free(jumbo_buffer_pa);
+ rte_free(jumbo_buf);
return -EFAULT;
}
- xdev->jumbo_buffer_pa = jumbo_buffer_pa;
- xdev->jumbo_buffer_va = jumbo_buffer_va;
+ xdev->jumbo_buf = jumbo_buf;
+ xdev->jumbo_iova = jumbo_iova;
}
for (i = 0; (i != wqe_n); ++i) {
@@ -246,7 +246,7 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
if (rx_ds_num != 1) {
seg_next = seg + 1;
*seg_next = (struct xsc_wqe_data_seg){
- .va = rte_cpu_to_le_64((uint64_t)jumbo_buffer_va),
+ .va = rte_cpu_to_le_64(jumbo_iova),
.seg_len = rte_cpu_to_le_32(XSC_MAX_RECV_LEN - seg_len),
.lkey = 0,
};
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 1/3] net/xsc: fix jumbo buffer allocation and leak
2026-11-16 6:58 [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-16 6:58 ` [PATCH v2 2/3] net/xsc: fix leak and missing null check Renyong Wan
2026-11-16 6:58 ` [PATCH v2 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
@ 2026-11-16 6:58 ` Renyong Wan
2026-11-16 18:46 ` [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger
3 siblings, 0 replies; 6+ messages in thread
From: Renyong Wan @ 2026-11-16 6:58 UTC (permalink / raw)
To: dev; +Cc: stephen, nana, qianr, zhangxx, xudw, stable
The jumbo buffer is allocated inside the WQE loop, so a device without
IOVA retries it on every WQE and logs an error each time. The fallback
also hands XSC_MAX_RECV_LEN bytes to a segment that points into an
mbuf, which is a DMA overrun.
Allocate it once before the loop and fail the queue start on error.
It is never freed on close either, so free it in xsc_dev_uninit().
Fixes: 0ff4b93c318f ("net/xsc: support device start")
Cc: stable@dpdk.org
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
drivers/net/xsc/xsc_dev.c | 1 +
drivers/net/xsc/xsc_rx.c | 47 ++++++++++++++++++++++-----------------
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 478f4895..6bd12510 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -345,6 +345,7 @@ xsc_dev_uninit(struct xsc_dev *xdev)
PMD_INIT_FUNC_TRACE();
xsc_dev_pct_uninit(xdev);
xsc_dev_close(xdev, XSC_DEV_REPR_ID_INVALID);
+ rte_free(xdev->jumbo_buffer_pa);
rte_free(xdev);
}
diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c
index 13b2e269..5baeedf1 100644
--- a/drivers/net/xsc/xsc_rx.c
+++ b/drivers/net/xsc/xsc_rx.c
@@ -195,7 +195,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
return nb_pkts;
}
-static void
+static int
xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
{
const uint32_t wqe_n = rxq_data->wqe_s;
@@ -211,6 +211,24 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
volatile struct xsc_wqe_data_seg *seg;
volatile struct xsc_wqe_data_seg *seg_next;
+ if ((rx_ds_num != 1) && (jumbo_buffer_va == NULL)) {
+ jumbo_buffer_pa = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
+ if (jumbo_buffer_pa == NULL) {
+ PMD_DRV_LOG(ERR, "Failed to malloc jumbo_buffer");
+ return -ENOMEM;
+ }
+
+ jumbo_buffer_va = (void *)rte_malloc_virt2iova(jumbo_buffer_pa);
+ if ((rte_iova_t)jumbo_buffer_va == RTE_BAD_IOVA) {
+ PMD_DRV_LOG(ERR, "Failed to get IOVA of jumbo_buffer");
+ rte_free(jumbo_buffer_pa);
+ return -EFAULT;
+ }
+
+ xdev->jumbo_buffer_pa = jumbo_buffer_pa;
+ xdev->jumbo_buffer_va = jumbo_buffer_va;
+ }
+
for (i = 0; (i != wqe_n); ++i) {
mbuf = (*rxq_data->elts)[i];
seg = &((volatile struct xsc_wqe_data_seg *)rxq_data->wqes)[i * rx_ds_num];
@@ -227,25 +245,6 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
if (rx_ds_num != 1) {
seg_next = seg + 1;
- if (jumbo_buffer_va == NULL) {
- jumbo_buffer_pa = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
- if (jumbo_buffer_pa == NULL) {
- /* Rely on mtu */
- seg->seg_len = XSC_MAX_RECV_LEN;
- PMD_DRV_LOG(ERR, "Failed to malloc jumbo_buffer");
- continue;
- } else {
- jumbo_buffer_va =
- (void *)rte_malloc_virt2iova(jumbo_buffer_pa);
- if ((rte_iova_t)jumbo_buffer_va == RTE_BAD_IOVA) {
- seg->seg_len = XSC_MAX_RECV_LEN;
- PMD_DRV_LOG(ERR, "Failed to turn jumbo_buffer");
- continue;
- }
- }
- xdev->jumbo_buffer_pa = jumbo_buffer_pa;
- xdev->jumbo_buffer_va = jumbo_buffer_va;
- }
*seg_next = (struct xsc_wqe_data_seg){
.va = rte_cpu_to_le_64((uint64_t)jumbo_buffer_va),
.seg_len = rte_cpu_to_le_32(XSC_MAX_RECV_LEN - seg_len),
@@ -264,6 +263,8 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
recv_db.next_pid = wqe_n << log2ds;
recv_db.qp_num = rxq_data->qpn;
rte_write32(rte_cpu_to_le_32(recv_db.recv_data), rxq_data->rq_db);
+
+ return 0;
}
static int
@@ -484,7 +485,11 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id)
rxq_data->qpn = rqn_base + i;
xsc_dev_modify_qp_status(xdev, rxq_data->qpn, 1, XSC_CMD_OP_RTR2RTS_QP);
- xsc_rxq_initialize(xdev, rxq_data);
+ ret = xsc_rxq_initialize(xdev, rxq_data);
+ if (ret != 0) {
+ rte_errno = -ret;
+ goto set_qp_fail;
+ }
rxq_data->cq_ci = 0;
PMD_DRV_LOG(INFO, "Port %d create rx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%u",
port_id,
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer
2026-11-16 6:58 [PATCH v2 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
` (2 preceding siblings ...)
2026-11-16 6:58 ` [PATCH v2 1/3] net/xsc: fix jumbo buffer allocation and leak Renyong Wan
@ 2026-11-16 18:46 ` Stephen Hemminger
3 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2026-11-16 18:46 UTC (permalink / raw)
To: Renyong Wan; +Cc: dev, nana, qianr, zhangxx, xudw
On Mon, 16 Nov 2026 06:58:43 -0000
"Renyong Wan" <wanry@yunsilicon.com> wrote:
> v2 addresses the issues raised in the AI review of v1:
> - allocate the jumbo buffer once per device, fail the queue setup when
> there is no IOVA, and free it on device close
> - fix the leak in xsc_dev_init() and the unchecked rte_malloc_socket()
> - rename the jumbo buffer fields, they held the opposite of what their
> names say
>
> Renyong Wan (3):
> net/xsc: fix jumbo buffer allocation and leak
> net/xsc: fix leak and missing null check
> net/xsc: rename jumbo buffer fields
>
> drivers/net/xsc/xsc_dev.c | 2 ++
> drivers/net/xsc/xsc_dev.h | 4 +--
> drivers/net/xsc/xsc_ethdev.c | 6 ++++
> drivers/net/xsc/xsc_rx.c | 53 ++++++++++++++++++++----------------
> 4 files changed, 39 insertions(+), 26 deletions(-)
Still has one AI reported error.
Subject: Re: [PATCH v2 1/3] net/xsc: fix jumbo buffer allocation and leak
Series applies to main and each commit builds with -Dwerror=true.
The allocation rework in 1/3 and the rename in 3/3 look right.
Patches 2/3 and 3/3 have no findings.
[PATCH v2 1/3] net/xsc: fix jumbo buffer allocation and leak
Error: the leak is not fixed. xsc_dev_uninit() is only called from
the probe error path in xsc_ethdev_init(), where the jumbo buffer
can never have been allocated (rte_zmalloc'd xdev, port never
started). The normal remove path is xsc_ethdev_uninit(), which does
not call xsc_dev_uninit(); it frees xdev directly:
ret |= xsc_ethdev_close(eth_dev);
xsc_dev_pct_uninit(priv->xdev);
rte_free(priv->xdev);
So the buffer still leaks on every device removal. Free it there as
well (with 3/3 applied, jumbo_buf):
ret |= xsc_ethdev_close(eth_dev);
xsc_dev_pct_uninit(priv->xdev);
rte_free(priv->xdev->jumbo_buffer_pa);
rte_free(priv->xdev);
Calling xsc_dev_uninit() from xsc_ethdev_uninit() instead would run
xsc_dev_close() a second time, so the direct free is the simpler
fix. Keeping the rte_free() in xsc_dev_uninit() is harmless.
Update the commit message accordingly; "free it in xsc_dev_uninit()"
describes the path that does not run on close or removal.
^ permalink raw reply [flat|nested] 6+ messages in thread