|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:38:32 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 lower-bound check to prevent negative GPIO numbers from causing out-of-bounds array access.

---

## Errors

None identified.

---

## Warnings

### 1. Missing explicit NULL comparison (C coding style)

**File:** `drivers/raw/cnxk_gpio/cnxk_gpio.c`  
**Line:** `return (gpio >= 0) && (gpio < gpiochip->num_gpios) && gpiochip->gpios[gpio];`

The third condition uses implicit truthiness on a pointer.
DPDK style requires explicit comparison: `gpiochip->gpios[gpio] != NULL`.

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

This is typically caught by coccinelle scripts in `devtools/cocci/`, but should be corrected before merge.

---

## Info

### Release Notes

This is a bug fix for existing functionality. The patch correctly includes `Cc: stable at dpdk.org` for backporting. No release notes entry is required for bug fixes that don't affect public API or add new features.

### Correctness

The fix correctly addresses the out-of-bounds access issue:
- Negative `gpio` values would previously index `gpiochip->gpios[]` with a negative subscript (undefined behavior in C)
- The added `(gpio >= 0)` check prevents this
- The check is placed first in the short-circuit AND chain, so it guards both subsequent conditions

The fix is minimal and appropriate for the issue described.

---

## Overall Assessment

The patch is functionally correct and addresses a real bug. Only one style issue needs correction (explicit NULL comparison). The fix is appropriate for stable backport.


More information about the test-report mailing list