* [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* Re: [PATCH] gpio: pxa: Publish the legacy IRQ domain after GPIO setup succeeds
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
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 10:01 UTC (permalink / raw)
To: Tian Xuechen; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] gpio: pxa: NULL pointer dereference in pxa_gpio_probe_dt() [1]
--
commit b66797fa4e010f68c27fe464b77da0fdb10324ea
Author: Tian Xuechen <202300460064@mail.sdu.edu.cn>
gpio: pxa: Publish the legacy IRQ domain after GPIO setup succeeds
This commit creates the legacy IRQ domain after GPIO chip registration
succeeds, uses devm_gpiochip_add_data(), and disables manual driver unbind.
> diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
> index 17e95ee4fef64..1689a05da6c95 100644
> --- a/drivers/gpio/gpio-pxa.c
> +++ b/drivers/gpio/gpio-pxa.c
[ ... ]
> @@ -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;
> -
[Severity: High]
This problem wasn't introduced by this patch, but can pxa_gpio_probe() ->
pxa_gpio_probe_dt() cause a NULL pointer dereference [1] on a non-DT
platform device without platform data?
When dev_get_platdata() returns NULL, pxa_gpio_probe() falls back to
pxa_gpio_probe_dt(), which dereferences the result of
of_device_get_match_data() without checking for NULL:
drivers/gpio/gpio-pxa.c:pxa_gpio_probe_dt() {
...
gpio_id = of_device_get_match_data(&pdev->dev);
gpio_type = gpio_id->type;
...
}
[1] https://sashiko.dev/#/bug/linux-ddf1292a-99b3-45e7-9575-418a500c6bcf
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129094739.1691742-1-202300460064@mail.sdu.edu.cn?part=1
^ permalink raw reply [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