[PATCH 2/2] gpio: davinci: allocate bank IRQ data before installing handlers
From: Sahaj Chaudhari
Date: Mon Nov 09 2026 - 14:51:59 EST
If allocation fails partway through bank setup, previously installed
chained handlers still point at devm-managed data that is released when
probe fails. Allocate the complete bank-data array before installing the
first chained handler so an allocation failure leaves no handlers behind.
This fixes the probe-failure path; it does not change ordinary device
removal.
Fixes: b5cf3fd827d2 ("gpio: davinci: Redesign driver to accommodate ngpios in one gpio chip")
Signed-off-by: Sahaj Chaudhari <sahaj123.sc@xxxxxxxxx>
---
drivers/gpio/gpio-davinci.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index caeecfc3df20..751c0e3a9676 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -550,6 +550,13 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
* Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we
* then chain through our own handler.
*/
+ irqdata = devm_kcalloc(dev, DIV_ROUND_UP(ngpio, 16),
+ sizeof(*irqdata), GFP_KERNEL);
+ if (!irqdata) {
+ irq_domain_remove(chips->irq_domain);
+ return -ENOMEM;
+ }
+
for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 16) {
/* disabled by default, enabled only as needed
* There are register sets for 32 GPIOs. 2 banks of 16
@@ -564,21 +571,12 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
* gpio irqs. Pass the irq bank's corresponding controller to
* the chained irq handler.
*/
- irqdata = devm_kzalloc(&pdev->dev,
- sizeof(struct
- davinci_gpio_irq_data),
- GFP_KERNEL);
- if (!irqdata) {
- irq_domain_remove(chips->irq_domain);
- return -ENOMEM;
- }
-
- irqdata->regs = g;
- irqdata->bank_num = bank;
- irqdata->chip = chips;
+ irqdata[bank].regs = g;
+ irqdata[bank].bank_num = bank;
+ irqdata[bank].chip = chips;
irq_set_chained_handler_and_data(chips->irqs[bank],
- gpio_irq_handler, irqdata);
+ gpio_irq_handler, &irqdata[bank]);
binten |= BIT(bank);
}
--
2.43.0