|WARNING| net/ice: fix PHY capabilities buffer leak
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Wed Sep 30 19:30:36 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/170377
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-09-30
# DPDK Patch Review: net/ice: fix PHY capabilities buffer leak
## Summary
This patch fixes a resource leak in the ICE driver where a PHY capabilities buffer is allocated before validating `hw->port_info`, causing the buffer to leak if the validation fails.
---
## Errors
### 1. Resource leak on remaining error paths
**File:** `drivers/net/intel/ice/ice_ethdev.c`
**Function:** `ice_phy_conf_link()`
The patch fixes the leak when `pi` is NULL, but does NOT fix the leak when `ice_fw_supports_report_dflt_cfg()` or `ice_aq_get_phy_caps()` fails. After this patch, if those functions return an error, the code returns early without freeing `phy_caps`.
**Why it matters:** Every error path after `ice_malloc()` must free the buffer. Missing even one error path creates a resource leak.
**Suggested fix:**
```c
if (!pi) {
ice_free(hw, phy_caps);
return -EIO;
}
/* ... later in the function ... */
if (ice_fw_supports_report_dflt_cfg(pi->hw))
err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
phy_caps, NULL);
else
err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
phy_caps, NULL);
if (err) {
ice_free(hw, phy_caps);
return err; /* or appropriate error code */
}
/* ... continue with normal cleanup at function end ... */
```
Alternatively, use a `goto cleanup` pattern with a single cleanup label at the end of the function that always frees `phy_caps` before returning.
---
## Warnings
### 1. Inconsistent error code return
**File:** `drivers/net/intel/ice/ice_ethdev.c`
**Function:** `ice_phy_conf_link()`
The patch changes the NULL check to return `-EIO`, but the allocation failure returns `ICE_ERR_NO_MEMORY`. The function should use a consistent error code convention (either all negative errno values or all ICE_ERR_* values).
**Suggested fix:** Review the function's callers to determine the expected error code type, then make all error returns consistent. If callers expect errno-style codes, change `ICE_ERR_NO_MEMORY` to `-ENOMEM`. If they expect ICE_ERR_* codes, change `-EIO` to an appropriate `ICE_ERR_*` constant.
---
## Info
### 1. Alternative cleanup pattern
Consider refactoring the function to use a single cleanup path with a label at the end. This is a common pattern in DPDK error handling and makes it harder to accidentally introduce resource leaks:
```c
static int
ice_phy_conf_link(struct ice_hw *hw, ...)
{
struct ice_aqc_get_phy_caps_data *phy_caps;
int ret = 0;
...
if (!pi)
return -EIO;
phy_caps = ice_malloc(hw, sizeof(*phy_caps));
if (!phy_caps)
return -ENOMEM;
if (ice_fw_supports_report_dflt_cfg(pi->hw))
err = ice_aq_get_phy_caps(...);
else
err = ice_aq_get_phy_caps(...);
if (err) {
ret = err;
goto cleanup;
}
/* ... rest of function logic ... */
cleanup:
ice_free(hw, phy_caps);
return ret;
}
```
This pattern ensures `phy_caps` is always freed, regardless of which error path is taken.
---
## Final Assessment
**The patch addresses one specific leak but introduces a partial fix that leaves other leaks unresolved.** The reordered NULL check is correct, but the function still leaks `phy_caps` on other error paths. The patch should be revised to fix ALL error paths after the allocation, not just the NULL check path.
More information about the test-report
mailing list