|WARNING| raw/cnxk_gpio: fix out of bound access for negative gpio

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Fri Aug 7 12:33:23 CEST 2026


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

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-07

# DPDK Patch Review

## Summary
This patch adds a negative value check to `cnxk_gpio_valid()` to prevent out-of-bounds array access when `gpio` is negative.

---

## Errors

### 1. Implicit Boolean Comparison (C Coding Style)

**Issue:** The pointer `gpiochip->gpios[gpio]` is tested for truthiness without explicit NULL comparison.

**Why it matters:** DPDK coding standards require explicit comparison against NULL for pointers (per AGENTS.md "Comparisons and Boolean Logic" section). While the existing code already has this pattern, the patch modifies the line and should fix it.

**Fix:**
```c
return (gpio >= 0) && (gpio < gpiochip->num_gpios) && (gpiochip->gpios[gpio] != NULL);
```

---

## Warnings

None.

---

## Info

### Logic Flow Observation

The bound checks use short-circuit evaluation correctly: `gpio >= 0` is checked first, then `gpio < gpiochip->num_gpios`, ensuring the array index is valid before dereferencing `gpiochip->gpios[gpio]`. This is the correct order for safety.

---

## Overall Assessment

The patch correctly addresses the security issue of negative array indices. The only required change is to make the pointer comparison explicit per DPDK style guidelines.


More information about the test-report mailing list