Skip to contentSkip to conversation

gpio: timberdale: fix off-by-one in IRQ type boundary check

PATCH Applied Junjie Cao 2 participants 2 messages Aug 25, 2025 – Aug 26, 2025 GPIO

lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

PATCH 1/1 gpio: timberdale: fix off-by-one in IRQ type boundary check

timbgpio_irq_type() currently accepts offset == ngpio, violating gpiolib's [0..ngpio-1] contract. This can lead to undefined behavior when computing '1 << offset', and it is also inconsistent with users that iterate with for_each_set_bit(..., ngpio).

Tighten the upper bound to reject offset == ngpio. No functional change for in-range offsets.

---
 drivers/gpio/gpio-timberdale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-timberdale.c +1 -1
index 679e27f00ff6..f488939dd00a 100644
@@ -137,7 +137,7 @@ static int timbgpio_irq_type(struct irq_data *d, unsigned trigger)
 	u32 ver;
 	int ret = 0;
 
-	if (offset < 0 || offset > tgpio->gpio.ngpio)
+	if (offset < 0 || offset >= tgpio->gpio.ngpio)
 		return -EINVAL;
 
 	ver = ioread32(tgpio->membase + TGPIO_VER);
Signature · 1 line
2.43.0
#1 lore raw

From: Bartosz Golaszewski <[email protected]>

Quoted 9 lines · Junjie Cao

timbgpio_irq_type() currently accepts offset == ngpio, violating gpiolib's [0..ngpio-1] contract. This can lead to undefined behavior when computing '1 << offset', and it is also inconsistent with users that iterate with for_each_set_bit(..., ngpio).

Tighten the upper bound to reject offset == ngpio. No functional change for in-range offsets.

[...]

Applied, thanks!

[1/1] gpio: timberdale: fix off-by-one in IRQ type boundary check

      https://git.kernel.org/brgl/linux/c/810e154d90f44127239957b06ee51a55553a5815

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>