|WARNING| [2/2] test/af_packet: add test for fanout modes
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Fri Oct 23 19:21:26 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172022
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-10-23
# Review of DPDK AF_PACKET Patch Series
## PATCH 1/2: net/af_packet: do not set rollover flag in rollover mode
### ERRORS
**Use of bitwise AND-assign on potentially uninitialized variable**
In `get_fanout_mode()`, the variable `load_balance` is assigned a value conditionally based on string comparisons, but the code path for "rollover" mode performs a bitwise AND operation (`&=`) on `load_balance` before any OR operation:
```c
} else if (!strcmp(fanout_mode, "rollover")) {
/* setting both is rejected by kernel */
load_balance &= ~PACKET_FANOUT_FLAG_ROLLOVER;
load_balance |= PACKET_FANOUT_ROLLOVER;
```
**Line 848**: `load_balance &= ~PACKET_FANOUT_FLAG_ROLLOVER;`
This assumes `load_balance` has been initialized prior to this function or earlier in the same function. Tracing the code path visible in the patch context, I cannot see where `load_balance` is initialized before the first conditional branch. If the first `strcmp` matches "rollover", the `&=` operates on an uninitialized value, which is undefined behavior.
**Suggested fix**: Initialize `load_balance` at the start of the function, or use a direct assignment instead of `&=` if the intent is to clear specific bits from a default value. If there's a default initialization outside the visible context, verify it occurs before any of these conditionals can execute.
---
## PATCH 2/2: test/af_packet: add test for fanout modes
### WARNINGS
**Missing error path cleanup**
In `test_af_packet_fanout_modes()`, if `rte_vdev_init()` succeeds but `rte_eth_dev_get_port_by_name()` returns an error (non-zero), the test asserts failure **without calling `rte_vdev_uninit()`** for that iteration.
```c
ret = rte_vdev_init("net_af_packet_fanout", devargs);
TEST_ASSERT(ret == 0,
"Failed to create af_packet sockets with fanout_mode=%s: %d",
modes[i], ret);
ret = rte_eth_dev_get_port_by_name("net_af_packet_fanout", &test_port);
if (ret == 0)
rte_eth_dev_close(test_port);
rte_vdev_uninit("net_af_packet_fanout");
TEST_ASSERT(ret == 0,
"af_packet port with fanout_mode=%s has no port id: %d",
modes[i], ret);
```
**Lines 1022-1026**: If the first `TEST_ASSERT` (line 1018) fails, the macro returns immediately, leaving the vdev initialized. This leaks the vdev resource.
**Suggested fix**: Move `rte_vdev_uninit()` into an unconditional cleanup path or add a cleanup label to ensure it is called on all error paths:
```c
ret = rte_vdev_init("net_af_packet_fanout", devargs);
if (ret != 0) {
printf("Failed to create af_packet sockets with fanout_mode=%s: %d\n",
modes[i], ret);
return TEST_FAILED;
}
ret = rte_eth_dev_get_port_by_name("net_af_packet_fanout", &test_port);
if (ret == 0)
rte_eth_dev_close(test_port);
rte_vdev_uninit("net_af_packet_fanout");
TEST_ASSERT(ret == 0,
"af_packet port with fanout_mode=%s has no port id: %d",
modes[i], ret);
```
Alternatively, restructure to always call `uninit` before any failure return.
---
**Implicit comparison in test code**
**Line 1023**: `if (ret == 0)` is an explicit comparison, which is correct per DPDK style.
**Line 1018**: `TEST_ASSERT(ret == 0, ...)` uses explicit comparison, which is correct.
**Line 1026**: `TEST_ASSERT(ret == 0, ...)` uses explicit comparison, which is correct.
No style issues detected in this patch.
---
## Summary
**Patch 1/2**: Contains a potential correctness bug (use of `&=` on possibly uninitialized `load_balance`). This must be verified or fixed.
**Patch 2/2**: Contains a resource leak on the error path where `rte_vdev_init()` succeeds but the port lookup assertion fails.
Review-Result: ERROR
More information about the test-report
mailing list