mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] gpio: davinci: fix probe-time IRQ setup
@ 2026-11-24 13:36 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 ` [PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers Sahaj Chaudhari
  0 siblings, 2 replies; 3+ messages in thread
From: Sahaj Chaudhari @ 2026-11-24 13:36 UTC (permalink / raw)
  To: linusw, brgl
  Cc: linux-gpio, linux-kernel, j-keerthy, nsekhar, prabhakar.csengg,
	avinashphilip, sujithkv

This series fixes two independent probe-time bugs in the DaVinci GPIO
driver:

1. A file-global MMIO base can be overwritten by overlapping controller
   probes, causing BINTEN setup to target the wrong controller.
2. Per-bank IRQ data is allocated as chained handlers are installed. A
   later allocation failure can leave handlers pointing to devm-managed
   data freed during probe unwind.

The first patch derives BINTEN from the current controller's mapped bank.
The second allocates all IRQ data before installing any handlers.

---
Changes in v2:
- Rebase on current GPIO gpio/for-next, incorporating the upstream
  devm_kzalloc_obj() conversion as requested by Bartosz.
- Use devm_kzalloc_objs() for the upfront bank-data array in patch 2.
- Add Linus Walleij's Reviewed-by to both patches.
- Keep the pre-existing GPIO-count bounds issue reported by Sashiko
  separate, as requested by Linus.
- Repeat baseline/fixed fault regressions and parent-handler dispatch
  coverage on AM642.

Previous version:
https://lore.kernel.org/all/20261109194910.2282454-1-sahaj123.sc@gmail.com/

Testing:
- ARM64 W=1 driver builds passed for each fix and the series.
- A local ASan/UBSan harness ran the extracted probe and IRQ setup
  functions with mocked allocation, IRQ registration and 32-bit MMIO.
  Nested probes of 87/88-GPIO controllers and bank-allocation failures
  reproduced wrong targets and stale handlers; each fix passed
  independently.
- On AM642, instrumented baseline/fixed kernels reproduced wrong BINTEN
  targets and a stale chained handler under forced probe interleaving and
  allocation failure; the fixes passed. A private module also exercised
  the real parent handler on 12 banks via GIC pending-state injection.
  No electrical GPIO edges or child IRQ delivery were tested.

The AM642 tests used kernels with extra debug code to force these
failures; that code is not part of this series. On those 7.4 test
kernels, with and without the fixes, the mmio-mux driver at a40000
failed to probe with -22 using the vendor device tree. The board's
6.12 vendor kernel does not show this error. I have not found the
cause, so these runs were not a full-board check.

GitHub Copilot CLI was used during bug investigation, review, patch
preparation and testing, and to draft the emails and commit messages.

Sahaj Chaudhari (2):
  gpio: davinci: use controller-specific MMIO for BINTEN
  gpio: davinci: allocate bank IRQ data before installing handlers

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


base-commit: 0e1941b7d0b0a0405b16567678a9bc3b20be6340
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] gpio: davinci: use controller-specific MMIO for BINTEN
  2026-11-24 13:36 [PATCH v2 0/2] gpio: davinci: fix probe-time IRQ setup Sahaj Chaudhari
@ 2026-11-24 13:36 ` Sahaj Chaudhari
  2026-11-24 13:36 ` [PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers Sahaj Chaudhari
  1 sibling, 0 replies; 3+ messages in thread
From: Sahaj Chaudhari @ 2026-11-24 13:36 UTC (permalink / raw)
  To: linusw, brgl
  Cc: linux-gpio, linux-kernel, j-keerthy, nsekhar, prabhakar.csengg,
	avinashphilip, sujithkv

The file-global gpio_base can be overwritten when probes for multiple
DaVinci GPIO controllers overlap. The later IRQ setup can then write the
BINTEN register of a different controller.

Derive the BINTEN address from the current controller's mapped bank
instead of shared global state.

Fixes: 118150f22d6b ("gpio: davinci: move to platform device")
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 after the devm_kzalloc_obj() conversion.
  The fix itself is unchanged.
- Add Linus Walleij's Reviewed-by.

Previous version:
https://lore.kernel.org/all/20261109194910.2282454-2-sahaj123.sc@gmail.com/

Testing:
- ARM64 W=1 driver build and mocked nested-probe regression passed.
- Instrumented AM642 baseline selected two wrong BINTEN targets during
  forced probe interleaving; the fixed series selected all three correctly.
  See the cover letter for test scope and limitations.

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

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index b80c1a27d591..7961ddee9f40 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -43,7 +43,6 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
 
 #define BINTEN	0x8 /* GPIO Interrupt Per-Bank Enable Register */
 
-static void __iomem *gpio_base;
 static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0};
 
 struct davinci_gpio_irq_data {
@@ -168,6 +167,7 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 	unsigned int ngpio, nbank, nirq, gpio_unbanked;
 	struct davinci_gpio_controller *chips;
 	struct device *dev = &pdev->dev;
+	void __iomem *gpio_base;
 
 	/*
 	 * The gpio banks conceptually expose a segmented bitmap,
@@ -586,7 +586,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	 * BINTEN -- per-bank interrupt enable. genirq would also let these
 	 * bits be set/cleared dynamically.
 	 */
-	writel_relaxed(binten, gpio_base + BINTEN);
+	writel_relaxed(binten, chips->regs[0] - offset_array[0] + BINTEN);
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Sahaj Chaudhari @ 2026-11-24 13:36 UTC (permalink / raw)
  To: linusw, brgl
  Cc: linux-gpio, linux-kernel, j-keerthy, nsekhar, prabhakar.csengg,
	avinashphilip, sujithkv

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 2/2] gpio: davinci: allocate bank IRQ data before installing handlers Sahaj Chaudhari

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®