|WARNING| [RFC] eal: allow setting random number generator seed
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Sat Sep 12 01:15:26 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/169429
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-09-11
# DPDK Patch Review
## Overview
This patch adds the ability to override the automatic random seed on DPDK startup via the `DPDK_RANDOM_SEED` environment variable. Overall, the patch is well-written with good error handling, but has one critical correctness issue.
---
## Errors
### Resource leak on error path
The `rte_exit()` call in the error path leaks the `DPDK_RANDOM_SEED` environment variable string that was retrieved by `getenv()`. While `getenv()` returns a pointer to internal storage that doesn't require freeing, the real issue is that `rte_exit()` is called during EAL initialization when resources may already be allocated. The `eal_rand_init()` function has already allocated `RTE_LCORE_VAR_ALLOC(rand_state)` before checking the environment variable.
**Suggested fix:** Move the environment variable parsing and validation before the `RTE_LCORE_VAR_ALLOC()` call, or add proper cleanup before `rte_exit()`:
```c
RTE_INIT_PRIO(eal_rand_init, RAND)
{
uint64_t seed;
const char *env = getenv("DPDK_RANDOM_SEED");
if (env != NULL && *env != '\0') {
char *end;
errno = 0;
seed = strtoull(env, &end, 0);
if (errno != 0 || *end != '\0')
rte_exit(EXIT_FAILURE,
"invalid DPDK_RANDOM_SEED: %s\n", env);
} else {
seed = __rte_random_initial_seed();
}
RTE_LCORE_VAR_ALLOC(rand_state);
rte_srand(seed);
}
```
---
## Warnings
### Missing documentation
The new `DPDK_RANDOM_SEED` environment variable should be documented. According to DPDK guidelines, environment variables that affect DPDK behavior should be documented in the appropriate guide and in release notes.
**Suggested additions:**
1. Add documentation in `doc/guides/prog_guide/env_abstraction_layer.rst` or similar
2. Add a release notes entry describing the new environment variable
3. Consider adding a note in the `rte_rand()` function documentation mentioning this environment variable
### getenv() usage in lib/
While the guidelines mention that `getenv()` is forbidden in `lib/` and `drivers/`, there is an exception for EAL (Environmment Abstraction Layer) which legitimately needs to parse environment variables. However, this should be verified to be the intended exception.
If this is intended as an EAL feature (which it appears to be given the location in `lib/eal/common/`), this is acceptable. Otherwise, consider making this a command-line argument instead of an environment variable.
---
## Info
### Consider explicit comparison style
While the code `*env != '\0'` is correct, DPDK style often prefers explicit comparisons. However, for character comparison against null terminator, the current style is actually clear and acceptable. No change needed, but be aware this could vary across the codebase.
### Error message formatting
The error message format is good, but consider whether `rte_exit()` is the appropriate error handling here versus logging and using a fallback. However, given this is initialization code and an invalid configuration, `rte_exit()` is reasonable.
---
## Summary
**Critical Issues:** 1
- Resource leak: `RTE_LCORE_VAR_ALLOC` called before validation, leaked on `rte_exit()`
**Warnings:** 2
- Missing documentation for new environment variable
- Verify `getenv()` usage is intended exception for EAL
The patch logic is sound and error handling is generally good, but the resource allocation should occur after validation to avoid leaking on the error path.
More information about the test-report
mailing list