[PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers

From: Sahaj Chaudhari

Date: Tue Nov 24 2026 - 08:37:12 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")
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Signed-off-by: Sahaj Chaudhari <sahaj123.sc@xxxxxxxxx>
---
Changes in v2:
- Rebase onto GPIO gpio/for-next and use devm_kzalloc_objs() for the
upfront array, matching the upstream devm_kzalloc_obj() conversion.
- Add Linus Walleij's Reviewed-by.

Previous version:
https://lore.kernel.org/all/20261109194910.2282454-3-sahaj123.sc@xxxxxxxxx/

Testing:
- ARM64 W=1 driver build and mocked allocation-failure regression passed.
- Instrumented AM642 allocation failure left one handler on baseline and
none with the fixed series. The real parent handler was also exercised
on 12 banks. See the cover letter for test scope and limitations.

drivers/gpio/gpio-davinci.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 7961ddee9f40..15c6420d25c4 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_kzalloc_objs(dev, *irqdata,
+ DIV_ROUND_UP(ngpio, 16));
+ 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,19 +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_obj(&pdev->dev,
- struct davinci_gpio_irq_data);
- 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