|WARNING| graph: fix xstats of cloned nodes
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Wed Jul 8 13:58:47 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/166628
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-07-08
# DPDK Patch Review: graph: fix xstats of cloned nodes
## Summary
This patch fixes a bug where cloned graph nodes do not properly copy the `nb_xstats` field, resulting in cloned nodes reporting zero available xstats. The fix is a one-line addition to copy this field during node cloning.
---
## Errors
None.
---
## Warnings
### 1. Missing bounds check before copying xstat_desc entries
**Location:** `lib/graph/node.c:211-214`
The code copies `xstat_desc` entries in a loop controlled by `node->xstats->nb_xstats`, but this occurs **before** `reg->xstats->nb_xstats` is set. If the allocation of `reg->xstats->xstat_desc` was based on a different size or was uninitialized, this could result in out-of-bounds access.
**Current code:**
```c
reg->xstats->nb_xstats = node->xstats->nb_xstats;
for (i = 0; i < node->xstats->nb_xstats; i++)
if (rte_strscpy(reg->xstats->xstat_desc[i], node->xstats->xstat_desc[i],
RTE_NODE_XSTAT_DESC_SIZE) < 0)
```
**Context needed:** The allocation of `reg->xstats->xstat_desc` needs to be verified. If it is allocated based on `node->xstats->nb_xstats` just before this loop, then the patch placement is correct. However, the patch adds the assignment **after** the loop has already started iterating based on `node->xstats->nb_xstats`.
**Recommendation:** The assignment of `reg->xstats->nb_xstats` should occur **before** the loop that uses it as a bound. If the allocation happens earlier in the function based on this value, move the assignment to immediately after allocation and before the loop:
```c
/* After allocating reg->xstats->xstat_desc */
reg->xstats->nb_xstats = node->xstats->nb_xstats;
for (i = 0; i < reg->xstats->nb_xstats; i++)
if (rte_strscpy(reg->xstats->xstat_desc[i], node->xstats->xstat_desc[i],
RTE_NODE_XSTAT_DESC_SIZE) < 0)
goto free;
```
**Severity:** Warning (requires verification of surrounding allocation code to confirm safety; patch may have incorrect placement)
---
## Info
None.
---
## Overall Assessment
The patch addresses a real bug where `nb_xstats` is not copied during node cloning, which would cause cloned nodes to report zero xstats. However, the placement of the assignment within the function may be incorrect -- it appears after a loop that already depends on `node->xstats->nb_xstats` as its iteration bound. The assignment should occur before the loop to ensure consistency and correctness. Please verify the allocation and initialization sequence in the surrounding code.
More information about the test-report
mailing list