|WARNING| [v2, 3/3] test/power: fix nominal frequency check with amd-pstate
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Tue Sep 8 19:12:55 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/169261
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-09-08
# DPDK Patch Review
## Patch 1/3: power/amd_pstate: fix frequency matching for continuous scaling
### Errors
1. **Variable declared but overwritten before read** (amd_pstate_cpufreq.c:305-306)
```c
FILE *f;
// ...
open_core_sysfs_file(&f, "rw+", POWER_SYSFILE_SETSPEED, pi->lcore_id);
```
The variable `f` is declared uninitialized, then immediately passed to `open_core_sysfs_file()` which will overwrite it. This is acceptable as the function initializes the pointer, but the declaration should use `= NULL` for safety in case the function fails and the error path checks `f`.
2. **Potential FILE* leak on error path** (amd_pstate_cpufreq.c:356-357)
The new code sets `pi->f = f;` before calling `write_freq()`, but if `write_freq()` fails, the function jumps to `err:` which closes `f` and sets `pi->f = NULL`. However, between line 356 (`pi->f = f;`) and line 357 (`if (write_freq(pi, best_idx) < 0)`), if `write_freq()` fails, `pi->f` holds a stale pointer to `f` which will be closed. The error path correctly sets `pi->f = NULL` at line 365, so this is safe.
### Warnings
1. **Missing explicit NULL comparison** (amd_pstate_cpufreq.c:310, 363)
```c
open_core_sysfs_file(&f, "rw+", POWER_SYSFILE_SETSPEED, pi->lcore_id);
if (ret < 0) {
```
After `open_core_sysfs_file()`, the code checks `ret < 0` but never verifies `f != NULL`. While the function likely guarantees `f` is set on success, explicit NULL check would be safer:
```c
if (ret < 0 || f == NULL) {
```
2. **Code uses implicit NULL check** (amd_pstate_cpufreq.c:363)
```c
if (f != NULL)
fclose(f);
```
This is correct per DPDK style requiring explicit comparison.
### Info
1. **Improved error handling**: The patch correctly adds `errno` checking and `endptr` validation for `strtoul()`, addressing parse failure detection.
2. **Improved frequency matching logic**: Using nearest-match instead of exact-match is appropriate for continuous scaling drivers.
---
## Patch 2/3: power: check for errors when writing frequency
### Errors
None identified. The patch correctly replaces the unchecked `fprintf()`/`fflush()` sequence with `write_core_sysfs_s()` which performs checked writes.
### Warnings
1. **Buffer size for frequency string** (acpi_cpufreq.c:57, amd_pstate_cpufreq.c:60, cppc_cpufreq.c:66)
```c
char buf[16];
```
A `uint32_t` frequency in decimal requires at most 10 digits plus null terminator (11 bytes). The 16-byte buffer is adequate but could use a comment or named constant:
```c
#define FREQ_STR_MAX 16 /* max uint32_t is 10 digits + null */
```
### Info
1. **Correctness improvement**: The patch fixes a real bug where frequency write failures were silently ignored. The `write_core_sysfs_s()` helper already performs `fseek()`, `write()`, and `fflush()` with error checking.
---
## Patch 3/3: test/power: fix nominal frequency check with amd-pstate
### Errors
None identified.
### Warnings
None identified.
### Info
1. **Test fix aligns with driver behavior**: The change correctly adapts the test to handle variable frequency table layouts where nominal frequency is not at a fixed index.
---
## General Comments
1. **Release notes**: These are bug fixes targeting stable, so release notes are not required per guidelines.
2. **Fixes tags**: All patches have appropriate `Fixes:` and `Cc: stable at dpdk.org` tags.
3. **Code style**: Patches follow DPDK C style (hard tabs, function return type on own line, explicit comparisons where required).
4. **Testing**: Patch 3/3 adapts existing test infrastructure to handle the corrected driver behavior.
---
## Summary
**Patch 1/3**: One minor safety suggestion (initialize `f = NULL`), otherwise correct.
**Patch 2/3**: No issues. Fixes real correctness bug where errors were silently ignored.
**Patch 3/3**: No issues. Test update aligns with driver fixes.
All patches address real bugs (continuous frequency matching, unchecked error returns, test assumptions) and are appropriate for stable backport. The code changes are correct and follow DPDK coding standards.
More information about the test-report
mailing list