[PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel()

From: Peng Fan

Date: Thu Dec 03 2026 - 04:30:34 EST


From: Peng Fan <peng.fan@xxxxxxx>

The per-channel teardown sequence (detach the chained handler, dispose
all child IRQ mappings, dispose the parent mapping) is open-coded in
both the probe error path and imx_intmux_remove(). Factor it out into
imx_intmux_teardown_channel() so the two paths cannot diverge.

The helper takes the driver data directly: probe only calls
platform_set_drvdata() after the channel loop, so re-fetching it via
platform_get_drvdata() would dereference NULL on the error path.

No functional change.

Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/irqchip/irq-imx-intmux.c | 44 ++++++++++++++++------------------------
1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index eeba45f312be..cce21ac8c21d 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -200,6 +200,21 @@ static void imx_intmux_irq_handler(struct irq_desc *desc)
generic_handle_domain_irq(irqchip_data->domain, pos);
}

+static void imx_intmux_teardown_channel(struct intmux_data *data, int i)
+{
+ /*
+ * Mask the parent interrupt and wait for a handler that is already
+ * running to finish before its handler data, chip and mappings are
+ * torn down. irq_dispose_mapping() installs no_irq_chip before its
+ * own synchronize_irq(), which loses the GIC active-state check.
+ */
+ disable_irq(data->irqchip_data[i].irq);
+ irq_set_chained_handler_and_data(data->irqchip_data[i].irq, NULL, NULL);
+ for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
+ irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain, hwirq));
+ irq_dispose_mapping(data->irqchip_data[i].irq);
+}
+
static int imx_intmux_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
@@ -290,20 +305,8 @@ static int imx_intmux_probe(struct platform_device *pdev)

return 0;
out:
- while (i--) {
- /*
- * Mask the parent interrupt and wait for a handler that is
- * already running to finish before its data and mappings are
- * torn down.
- */
- disable_irq(data->irqchip_data[i].irq);
- irq_set_chained_handler_and_data(data->irqchip_data[i].irq,
- NULL, NULL);
- for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
- irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
- hwirq));
- irq_dispose_mapping(data->irqchip_data[i].irq);
- }
+ while (i--)
+ imx_intmux_teardown_channel(data, i);
pm_runtime_disable(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
err_disable_clk:
@@ -324,18 +327,7 @@ static void imx_intmux_remove(struct platform_device *pdev)
/* disable all interrupt sources of this channel */
if (ret >= 0)
writel_relaxed(0, data->regs + CHANIER(i));
- /*
- * Mask the parent interrupt and wait for a handler that is
- * already running to finish before its data and mappings are
- * torn down.
- */
- disable_irq(data->irqchip_data[i].irq);
- irq_set_chained_handler_and_data(data->irqchip_data[i].irq,
- NULL, NULL);
- for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
- irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
- hwirq));
- irq_dispose_mapping(data->irqchip_data[i].irq);
+ imx_intmux_teardown_channel(data, i);
}

pm_runtime_disable(&pdev->dev);

--
2.56.0