Compare
170aeff46fb54f41545c85a72aec525aebc79d44..205cccd06e545694754e1bf8d626ea96e742cd8a
gpio: mxc: fix race between gpiochip registration and IRQ domain setup
devm_gpiochip_add_data() makes the GPIO chip visible to consumers
immediately. Since the chip sets .to_irq = mxc_gpio_to_irq, which calls
irq_find_mapping(port->domain, offset), any to_irq() call between
gpiochip registration and IRQ domain creation will operate on a NULL
domain.
Fix by moving devm_gpiochip_add_data() after the IRQ domain and generic
irq chip are fully initialized, ensuring port->domain and the irq chip
handlers are ready before the chip becomes visible to consumers.
Fixes: d37a65bb4663 ("gpio/mxc: Move Freescale MXC gpio driver to drivers/gpio")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://patch.msgid.link/20261013-gpio-mxc-cleanup-v7-4-c4d769587d3e@nxp.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Peng Fan <peng.fan@nxp.com> · 2026-10-13 06:01 UTC · committed by Bartosz Golaszewski
1 file changed,
+9
−4
modified drivers/gpio/gpio-mxc.c
| @@ -500,10 +500,6 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
| 500 | 500 | else /* silence boot time warning */ | |
| 501 | 501 | port->gen_gc.gc.base = -1; | |
| 502 | 502 | ||
| 503 | - | err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port); | |
| 504 | - | if (err) | |
| 505 | - | goto out_bgio; | |
| 506 | - | ||
| 507 | 503 | irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id()); | |
| 508 | 504 | if (irq_base < 0) { | |
| 509 | 505 | err = irq_base; | |
| @@ -524,6 +520,15 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
| 524 | 520 | if (err < 0) | |
| 525 | 521 | goto out_irqdomain_remove; | |
| 526 | 522 | ||
| 523 | + | /* | |
| 524 | + | * Register the GPIO chip last: devm_gpiochip_add_data() makes the | |
| 525 | + | * chip visible to consumers immediately, so the IRQ domain and | |
| 526 | + | * generic irq chip must be ready before any to_irq() call. | |
| 527 | + | */ | |
| 528 | + | err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port); | |
| 529 | + | if (err) | |
| 530 | + | goto out_irqdomain_remove; | |
| 531 | + | ||
| 527 | 532 | list_add_tail(&port->node, &mxc_gpio_ports); | |
| 528 | 533 | ||
| 529 | 534 | mxc_update_irq_chained_handler(port, true); | |