|WARNING| [6/6] devtools: forbid direct use of sys/queue.h

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Thu Sep 17 20:11:42 CEST 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/169757

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-09-17

# DPDK Code Review - series.patch

Reviewing patches from Stephen Hemminger addressing use-after-free in bnxt driver, introducing rte_queue.h header, and related cleanup.

---

## Patch 1/6: net/bnxt: fix use after free when freeing filters

### Errors

**Use-after-free in list traversal:**
The code freed `filter` then passed it to `STAILQ_REMOVE`, which walks the list using the freed element's `next` pointer. This is a use-after-free bug.

The fix correctly defines `STAILQ_FOREACH_SAFE` locally, changes to use it, and swaps the order (remove from list before freeing).

### Warnings

None.

**Correctness:** The fix is correct.

---

## Patch 2/6: eal: add rte_queue.h with full set of list macros

### Errors

None identified. The new header is a verbatim copy of FreeBSD's `<sys/queue.h>` with debug/invariants support removed, which is appropriate.

### Warnings

**Missing `#ifdef __cplusplus` in new public header:**
The file includes C++-specific macros (`QUEUE_TYPEOF` switches between `struct type` and `class type`) but wraps them in `#ifdef __cplusplus` blocks internally in the macro definitions. This is correct. No warning needed.

**Release notes entry could be clearer about platform coverage:**
The note says "including the `_FOREACH_SAFE` variants which are not available in the system header on Linux" but does not explicitly state that musl and Windows had *no* `<sys/queue.h>` at all. Consider: "...on all platforms, including the `_FOREACH_SAFE` variants missing on glibc, and providing all macros on Windows and musl libc which have no such system header."

This is **Info**-level: the existing text is acceptable but could be more precise.

**`__containerof` fallback definition:**
The patch defines `__containerof` when the platform does not provide it. FreeBSD provides it in `<sys/cdefs.h>`. The definition matches `offsetof`-based `container_of` patterns used elsewhere in DPDK. Correct.

**Inclusion of `<stddef.h>`:**
The header includes `<stddef.h>` for `offsetof` and `NULL`. Correct.

**Suppress-each-other guard behavior:**
The comment explains that this header and `<sys/queue.h>` suppress each other via the shared `_SYS_QUEUE_H_` guard. On glibc, if `<sys/queue.h>` wins, users lose `_FOREACH_SAFE`. On musl/Windows, there is no system header so this always wins. The comment notes the issue clearly. No action required from reviewer.

---

## Patch 3/6: build: use rte_queue.h instead of sys/queue.h

### Errors

None. This is a mechanical substitution of `#include <sys/queue.h>` with `#include <rte_queue.h>` across 283 files. Scripted change, verified by successful build.

### Warnings

**`drivers/common/cnxk/roc_bphy_irq.c` removes `<sys/queue.h>` include but does not add `<rte_queue.h>`:**
Review shows `roc_bphy_irq.c` includes `"roc_api.h"`, which includes `"roc_platform.h"`, which now includes `<rte_queue.h>`. The include is not needed directly. Acceptable.

**Similar transitive include patterns in other driver files:**
Many files removed `<sys/queue.h>` without adding `<rte_queue.h>` because a common internal header now pulls it in. This is fine and reduces redundancy.

**`lib/eal/freebsd/include/rte_os.h`, `lib/eal/linux/include/rte_os.h`, `lib/eal/windows/include/rte_os.h` now include `<rte_queue.h>` with a comment:**
The comment states "Not used here, but included so that rte_queue.h wins the multiple inclusion guard race." This is correct and documents the load-bearing include. No issue.

**Windows stub `lib/eal/windows/include/sys/queue.h` removed:**
The commit message for patch 2/6 said "Leave a stub at the old Windows path... It is removed in the next commit." This is that removal. Correct.

---

## Patch 4/6: build: remove private FOREACH_SAFE definitions

### Errors

None. Ten files carried private `STAILQ_FOREACH_SAFE`, `LIST_FOREACH_SAFE`, or `TAILQ_FOREACH_SAFE` definitions. All are now redundant because `<rte_queue.h>` provides them. Removal is correct.

### Warnings

**`drivers/net/bnxt/bnxt_filter.c`:**
Patch 1 added a local `STAILQ_FOREACH_SAFE`. Patch 4 removes it. Correct sequencing.

---

## Patch 5/6: eal: deprecate RTE_TAILQ and RTE_STAILQ macro wrappers

### Errors

None.

### Warnings

**Deprecated macro definitions are now trivial aliases:**
The wrappers are redefined as plain `TAILQ_*` / `STAILQ_*` macros, not the extended ones, so they work even if a system `<sys/queue.h>` won the include guard race. Rationale in the comment is correct.

**`RTE_TAILQ_FOREACH_SAFE` open-coded instead of mapping to `TAILQ_FOREACH_SAFE`:**
Comment explains: glibc does not have `TAILQ_FOREACH_SAFE`, so it must be open-coded to work in all cases. Correct.

**Release notes and deprecation notice wording:**
Both clearly state the wrappers existed only for Windows compatibility and are now redundant. Removal planned for 27.11. Acceptable.

**Mechanical substitution of `RTE_TAILQ_*` to `TAILQ_*` across 66 files:**
Verified correct by spot checks. No issues.

**`rte_queue.h` gets a comment documenting the guard-race behavior inside DPDK:**
The comment in patch 5 clarifies that `rte_os.h` includes `<rte_queue.h>` early, so any DPDK header wins the race within the tree. Helpful clarification.

---

## Patch 6/6: devtools: forbid direct use of sys/queue.h

### Errors

None.

### Warnings

**Forbidden token check covers `lib drivers app examples`:**
Matches the scope of other forbidden token checks. Correct.

**`SKIP_FILES` includes `lib/eal/include/rte_queue.h`:**
Avoids flagging the comment in the new header itself. Correct.

**Documentation update in `coding_style.rst`:**
Changes example from `#include <sys/queue.h>` to `#include <rte_queue.h>` and adds explanation. Clear and correct.

---

## Cross-Patch Consistency

**Patch ordering:**
1. Fix bnxt bug (standalone, can be backported)
2. Add new header
3. Switch all includes
4. Remove private definitions
5. Deprecate wrappers
6. Forbid system header

This is the correct order. Each step depends only on prior ones.

**No orphaned code:**
All removed `FOREACH_SAFE` definitions had at least one usage converted in patch 3. No dead code left behind.

---

## Summary

**Errors:** None.

**Warnings:** None (the release notes wording suggestion in patch 2 is Info-level only).

**Info:**
- Patch 2 release notes could be slightly more explicit that musl/Windows had no `<sys/queue.h>` at all, not just a subset. Current text is acceptable.

**Overall Assessment:**
This is a well-structured patch series. The use-after-free fix in patch 1 is a valuable correctness improvement. The introduction of `rte_queue.h` solves a real portability problem (missing `_FOREACH_SAFE` on glibc, no header on musl/Windows). The mechanical conversion is clean, the deprecation path is clear, and the forbidden token check prevents regression. The series correctly sequences the changes and documents the rationale.

**Recommendation:** Accept with the optional Info-level suggestion on release notes wording.


More information about the test-report mailing list