Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpio: pxa: Publish the legacy IRQ domain after GPIO setup succeeds
@ 2026-11-29  9:47 Tian Xuechen
  2026-11-29 10:01 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tian Xuechen @ 2026-11-29  9:47 UTC (permalink / raw)
  To: robert.jarzmik, linusw, brgl, haojian.zhuang, arnd
  Cc: linux-gpio, liguangshuo

From: Tian Xuechen <202300460064@mail.sdu.edu.cn>

Probe errors and manual unbind can leave the legacy IRQ domain pointing
to the old GPIO controller.
Avoid leaving the IRQ domain behind on probe errors by creating it after
the last fallible GPIO setup step. Defer GPIO-to-IRQ lookups until then
and keep the built-in system GPIO controller bound once its IRQ and
syscore users are active.

This issue was found by our static analysis tool under development.

Fixes: 7a4d5079baf2 ("gpio: pxa: parse gpio from DTS file")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
 drivers/gpio/gpio-pxa.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 17e95ee4fef6..1689a05da6c9 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -248,8 +248,15 @@ static bool pxa_gpio_has_pinctrl(void)
 static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 {
 	struct pxa_gpio_chip *pchip = chip_to_pxachip(chip);
+	struct irq_domain *domain;
 
-	return irq_find_mapping(pchip->irqdomain, offset);
+	/* The GPIO chip is visible before the legacy domain is initialized. */
+	domain = smp_load_acquire(&pchip->irqdomain);
+
+	if (!domain)
+		return -EPROBE_DEFER;
+
+	return irq_find_mapping(domain, offset);
 }
 
 static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -370,7 +377,7 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio, void __iom
 		bank->regbase = regbase + BANK_OFF(i);
 	}
 
-	return gpiochip_add_data(&pchip->chip, pchip);
+	return devm_gpiochip_add_data(pchip->dev, &pchip->chip, pchip);
 }
 
 /* Update only those GRERx and GFERx edge detection register bits if those
@@ -612,6 +619,7 @@ static int pxa_gpio_probe(struct platform_device *pdev)
 	struct pxa_gpio_bank *c;
 	struct clk *clk;
 	struct pxa_gpio_platform_data *info;
+	struct irq_domain *domain;
 	void __iomem *gpio_reg_base;
 	int gpio, ret;
 	int irq0 = 0, irq1 = 0, irq_mux;
@@ -637,11 +645,6 @@ static int pxa_gpio_probe(struct platform_device *pdev)
 	if (!pxa_last_gpio)
 		return -EINVAL;
 
-	pchip->irqdomain = irq_domain_create_legacy(dev_fwnode(&pdev->dev), pxa_last_gpio + 1,
-						    irq_base, 0, &pxa_irq_domain_ops, pchip);
-	if (!pchip->irqdomain)
-		return -ENOMEM;
-
 	irq0 = platform_get_irq_byname_optional(pdev, "gpio0");
 	irq1 = platform_get_irq_byname_optional(pdev, "gpio1");
 	irq_mux = platform_get_irq_byname(pdev, "gpio_mux");
@@ -668,6 +671,13 @@ static int pxa_gpio_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	domain = irq_domain_create_legacy(dev_fwnode(&pdev->dev), pxa_last_gpio + 1,
+					  irq_base, 0, &pxa_irq_domain_ops, pchip);
+	if (!domain)
+		return -ENOMEM;
+	/* Publish the fully initialized domain to concurrent GPIO-to-IRQ lookups. */
+	smp_store_release(&pchip->irqdomain, domain);
+
 	/* clear all GPIO edge detects */
 	for_each_gpio_bank(gpio, c, pchip) {
 		writel_relaxed(0, c->regbase + GFER_OFFSET);
@@ -722,6 +732,7 @@ static struct platform_driver pxa_gpio_driver = {
 	.probe		= pxa_gpio_probe,
 	.driver		= {
 		.name	= "pxa-gpio",
+		.suppress_bind_attrs = true,
 		.of_match_table = of_match_ptr(pxa_gpio_dt_ids),
 	},
 	.id_table	= gpio_id_table,

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.43.0


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

end of thread, other threads:[~2026-11-29 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  9:47 [PATCH] gpio: pxa: Publish the legacy IRQ domain after GPIO setup succeeds Tian Xuechen
2026-11-29 10:01 ` sashiko-bot

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