From: Sahaj Chaudhari <sahaj123.sc@gmail.com>
To: linusw@kernel.org, brgl@kernel.org
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
j-keerthy@ti.com, nsekhar@ti.com, prabhakar.csengg@gmail.com,
avinashphilip@ti.com, sujithkv@ti.com
Subject: [PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers
Date: Tue, 24 Nov 2026 19:06:54 +0530 [thread overview]
Message-ID: <20261124121500.2cd5cbf30f89-3-sahaj123.sc@gmail.com> (raw)
In-Reply-To: <20261124121500.2cd5cbf30f89-1-sahaj123.sc@gmail.com>
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@kernel.org>
Signed-off-by: Sahaj Chaudhari <sahaj123.sc@gmail.com>
---
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@gmail.com/
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
prev parent reply other threads:[~2026-11-24 13:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:36 [PATCH v2 0/2] gpio: davinci: fix probe-time IRQ setup Sahaj Chaudhari
2026-11-24 13:36 ` [PATCH v2 1/2] gpio: davinci: use controller-specific MMIO for BINTEN Sahaj Chaudhari
2026-11-24 13:36 ` Sahaj Chaudhari [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124121500.2cd5cbf30f89-3-sahaj123.sc@gmail.com \
--to=sahaj123.sc@gmail.com \
--cc=avinashphilip@ti.com \
--cc=brgl@kernel.org \
--cc=j-keerthy@ti.com \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=prabhakar.csengg@gmail.com \
--cc=sujithkv@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®