|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:51:31 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
Reviewing patch: "raw/cnxk_gpio: fix out of bound access for negative gpio"
This patch adds a bounds check to reject negative GPIO numbers in `cnxk_gpio_valid()`.
---
## Errors
None found.
---
## Warnings
**Warning 1: Implicit comparison on pointer**
**Location:** `drivers/raw/cnxk_gpio/cnxk_gpio.c:798`
The code uses implicit truthiness on the pointer `gpiochip->gpios[gpio]`.
DPDK style requires explicit comparison against NULL.
**Current code:**
```c
return (gpio >= 0) && (gpio < gpiochip->num_gpios) && gpiochip->gpios[gpio];
```
**Should be:**
```c
return (gpio >= 0) && (gpio < gpiochip->num_gpios) && (gpiochip->gpios[gpio] != NULL);
```
This makes the NULL check explicit per DPDK coding standards.
Note: This is typically caught by coccinelle scripts, but should be fixed in this patch.
---
## Info
**Info 1: Parentheses are unnecessary**
The parentheses around `(gpio >= 0)` and `(gpio < gpiochip->num_gpios)` are not required
since `&&` has lower precedence than comparison operators.
However, they improve readability and are acceptable style, so this is informational only.
---
## Correctness Analysis
The patch correctly addresses the stated issue:
- **Before:** Only checked upper bound, allowing negative indices to cause out-of-bounds access on `gpiochip->gpios[gpio]`
- **After:** Rejects negative values, preventing the out-of-bounds access
The fix is correct and addresses a real bounds-checking bug.
No resource leaks, use-after-free, or other correctness issues identified.
---
## Overall Assessment
The patch is sound from a correctness perspective.
The only issue is the style violation of implicit pointer comparison (Warning 1),
which should be fixed to match DPDK coding standards.
More information about the test-report
mailing list