]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
gpio: timberdale: fix off-by-one in IRQ type boundary check
authorJunjie Cao <junjie.cao@intel.com>
Mon, 25 Aug 2025 09:08:50 +0000 (17:08 +0800)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 26 Aug 2025 10:03:09 +0000 (12:03 +0200)
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.

Signed-off-by: Junjie Cao <junjie.cao@intel.com>
Link: https://lore.kernel.org/r/20250825090850.127163-1-junjie.cao@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-timberdale.c

index 679e27f00ff60791233f6ceebaff12b31f8b8c9c..f488939dd00a8a7f332d3af27962a38a3b7e6ecf 100644 (file)
@@ -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);