Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] pinctrl: airoha: fix parent IRQ vs gpiochip registration order
@ 2026-12-02 13:08 Vikrant Yadav
  0 siblings, 0 replies; only message in thread
From: Vikrant Yadav @ 2026-12-02 13:08 UTC (permalink / raw)
  To: lorenzo, john, linusw
  Cc: angelogioacchino.delregno, benjamin.larsson, linux-mediatek,
	linux-gpio, Vikrant Yadav

The parent IRQ is requested before devm_gpiochip_add_data(), so the
handler is live while the gpiochip and its IRQ domain do not exist.

On unbind, devm releases resources in reverse order: gpiochip_remove()
runs first and frees the IRQ domain, while the shared parent IRQ is
still registered. gpiolib does not clear gc->irq.domain, so a late
interrupt makes generic_handle_domain_irq() use a stale pointer.

On probe, the handler can run before the gpiochip is added, while
gc->irq.domain is still NULL.

Register the gpiochip first and request the parent IRQ afterwards.
The IRQ is then requested only once the domain exists, and freed
before the domain is removed.

Fixes: 1c8ace2d0725 ("pinctrl: airoha: Add support for EN7581 SoC")
Signed-off-by: Vikrant Yadav <vikrantyadav4802@gmail.com>
Reviewed-by: John Crispin <john@phrozen.org>
---
Changes in v2:
- Fix description: domain pointer is stale (not NULL) after
  gpiochip_remove(); NULL case is on probe side (John Crispin)
- Collect Reviewed-by from John Crispin

Link to v1: https://lore.kernel.org/linux-gpio/20261201145624.30092-1-vikrantyadav4802@gmail.com/

 drivers/pinctrl/airoha/pinctrl-airoha.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/airoha/pinctrl-airoha.c b/drivers/pinctrl/airoha/pinctrl-airoha.c
index 32d4af044ae1..4a0d31a6e08c 100644
--- a/drivers/pinctrl/airoha/pinctrl-airoha.c
+++ b/drivers/pinctrl/airoha/pinctrl-airoha.c
@@ -390,12 +390,17 @@ static int airoha_pinctrl_add_gpiochip(struct airoha_pinctrl *pinctrl,
 	if (irq < 0)
 		return irq;
 
-	err = devm_request_irq(dev, irq, airoha_irq_handler, IRQF_SHARED,
-				dev_name(dev), pinctrl);
+	/*
+	 * Register the gpiochip (and thus the IRQ domain) before requesting
+	 * the parent IRQ. devm unwinds in reverse order, so free_irq() runs
+	 * before gpiochip_remove() and the handler never sees a missing domain.
+	 */
+	err = devm_gpiochip_add_data(dev, gc, pinctrl);
 	if (err)
 		return err;
 
-	return devm_gpiochip_add_data(dev, gc, pinctrl);
+	return devm_request_irq(dev, irq, airoha_irq_handler, IRQF_SHARED,
+				dev_name(dev), pinctrl);
 }
 
 /* pinmux callbacks */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 13:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:08 [PATCH v2] pinctrl: airoha: fix parent IRQ vs gpiochip registration order Vikrant Yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox