|WARNING| [v2] net/bnxt: add bounds checks for FW-supplied IDs

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Tue Oct 13 22:00:21 CEST 2026


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

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-10-13

# DPDK Patch Review

## ERRORS

**1. Wrong variable used in bounds check (Error)**

Line 211: `if (func->phy_port_id >= port_db->phy_port_cnt)`

This check reads `func->phy_port_id` before it has been assigned.
Looking at the code flow: `phy_port_id` is obtained via `bnxt_pmd_get_phy_port_id()` call,
but that call happens *after* this bounds check (not shown in the patch context,
but necessarily must occur between lines 208 and the usage at line 217+).
The check should use the value returned from `bnxt_pmd_get_phy_port_id()` directly,
not `func->phy_port_id` which is either uninitialized or stale.

Either move this check to after the `phy_port_id` assignment,
or (if the assignment is in the omitted context) verify the raw value before assignment:

```c
phy_port_id = bnxt_pmd_get_phy_port_id(port_id);
if (phy_port_id >= port_db->phy_port_cnt) {
	BNXT_DRV_DBG(ERR, "Invalid phy_port_id %u", phy_port_id);
	return -EINVAL;
}
func->phy_port_id = phy_port_id;
```

---

## WARNINGS

**1. Missing bounds check before first use of drv_func_id (Warning)**

Line 167: `func = &port_db->ulp_func_id_tbl[intf->drv_func_id];`

The bounds check at line 162 validates `intf->drv_func_id`, but the array index is used at line 167.
If `bnxt_pmd_get_fw_func_id()` returns a value >= `BNXT_PORT_DB_MAX_FUNC`,
the bounds check correctly rejects it, but there is a logic issue:
the check occurs after the function call but before the array access is safe.

The current code is:
```c
intf->drv_func_id = bnxt_pmd_get_fw_func_id(...);
if (intf->drv_func_id >= BNXT_PORT_DB_MAX_FUNC) {  // check
	return -EINVAL;
}
func = &port_db->ulp_func_id_tbl[intf->drv_func_id];  // use
```

This is actually correct as written -- the check comes before the use.
However, for clarity and to match the pattern in the `vf_func_id` block,
consider fetching into a local variable first:

```c
uint16_t drv_func_id = bnxt_pmd_get_fw_func_id(port_id, BNXT_ULP_INTF_TYPE_INVALID);
if (drv_func_id >= BNXT_PORT_DB_MAX_FUNC) {
	BNXT_DRV_DBG(ERR, "Invalid drv_func_id %u", drv_func_id);
	return -EINVAL;
}
intf->drv_func_id = drv_func_id;
func = &port_db->ulp_func_id_tbl[drv_func_id];
```

This is a style suggestion, not a correctness bug. The existing code is safe.

---

## INFO

None.

---

## Summary

The patch correctly adds bounds checks for firmware-supplied IDs to prevent out-of-bounds array access.
However, the `phy_port_id` check appears to read the field before it is assigned,
which is either a use-before-init bug or indicates the assignment is in code not shown in the patch.
Verify the assignment occurs before line 211, or move the check to after the assignment.

Review-Result: ERROR


More information about the test-report mailing list