[PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe()

From: Lee Jones

Date: Thu Dec 03 2026 - 15:56:27 EST


davinci_gpio_probe() validates nirq against MAX_INT_PER_BANK (32) but
never bounds ngpio against MAX_REGS_BANKS (5, supporting at most 160
GPIOs). A larger ti,ngpio value causes out-of-bounds reads past
offset_array[] and out-of-bounds writes past chips->regs[] and
chips->context[].

Reject ngpio values greater than MAX_REGS_BANKS * 32 with -EINVAL and
size offset_array with MAX_REGS_BANKS.

Fixes: 8f7cf8c65746 ("gpio: davinci: Remove gpio2regs function")
Closes: https://sashiko.dev/#/bug/linux-59cf1b6f-2241-467c-a82a-93a3d1bf5d16
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/gpio/gpio-davinci.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 5f24367ad9af..f1f2b8f75761 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -43,7 +43,9 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);

#define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */

-static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0};
+static unsigned int offset_array[MAX_REGS_BANKS] = {
+ 0x10, 0x38, 0x60, 0x88, 0xb0,
+};

struct davinci_gpio_irq_data {
void __iomem *regs;
@@ -179,6 +181,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n");
if (ngpio == 0)
return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n");
+ if (ngpio > MAX_REGS_BANKS * 32)
+ return dev_err_probe(dev, -EINVAL, "Too many GPIOs\n");

/*
* If there are unbanked interrupts then the number of
--
2.56.1.911.g883d8bcb20-goog