Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management
@ 2026-12-03  9:29 Peng Fan
  2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

When I worked on guard_chained_irq patch, sashiko reported pre-exist
issues in imx-intmux driver. So I gave a look on this driver and found
more that need to be addressed.

Even there are a few fixes, but I think they are not critial for current
release cycle.

The first patch avoids creating parent IRQ mappings while counting channels.
It counts the entries with of_irq_count() and resolves each parent lazily
with of_irq_get() in the channel loop, preserving -EPROBE_DEFER.

The next two patches fix the removal and probe error paths. Both mask the
parent interrupt, wait for an in-flight chained handler, detach it, dispose
the child mappings, and release the parent mapping. The probe error path
also unwinds the initialized channels, tears down runtime PM, and enables
the clock before touching runtime PM so that a clock failure cannot leave
the usage counter unbalanced; a pm_runtime_set_active() failure is
propagated after unwinding.

The next three patches tighten the device-tree input handling: reject a zero
channel count, return -EINVAL instead of WARNing on malformed interrupt
specifiers (including source numbers beyond the 32 inputs), and mark the
multiplexed interrupts as level-triggered to match handle_level_irq() and
the type advertised by xlate().

The last two patches are cleanups with no functional change: use
devm_irq_domain_create_linear() for the per-channel domains and factor the
per-channel teardown into a helper shared by the probe error and remove
paths.

The teardown assumes the default fw_devlink=on/rpm behaviour, where managed
device links unbind consumers before the interrupt controller so that
consumers release their IRQ actions first. With fw_devlink=off or
permissive, an active consumer can keep its IRQ actions and threads while
child mappings are disposed, and a concurrently probing consumer can race
with the deferred domain removal; those configurations are not supported by
this series.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Changes in v2:
- Add a patch to avoid creating parent IRQ mappings while counting channels,
  using of_irq_count() and lazy of_irq_get().
- Rework the zero channel count check for of_irq_count().
- Drain in-flight chained handlers before detaching them in the remove and
  probe error paths.
- Check pm_runtime_set_active() and enable the clock before runtime PM.
- Reject malformed interrupt specifiers in xlate instead of WARNing.
- Correct the devm IRQ domain lifetime description in the commit message.
- Document that the teardown relies on fw_devlink=on/rpm consumer ordering.
- Link to v1: https://lore.kernel.org/r/20261117-imx-intmux-v1-0-189e7e0ad98d@nxp.com

---
Peng Fan (8):
      irqchip/imx-intmux: Don't create parent mappings while counting channels
      irqchip/imx-intmux: Dispose IRQ mappings on remove
      irqchip/imx-intmux: Fix probe error path
      irqchip/imx-intmux: Reject zero channel count
      irqchip/imx-intmux: Mark input interrupts as level-triggered
      irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers
      irqchip/imx-intmux: Use devm_irq_domain_create_linear()
      irqchip/imx-intmux: Factor out imx_intmux_teardown_channel()

 drivers/irqchip/irq-imx-intmux.c | 70 ++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 21 deletions(-)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261116-imx-intmux-7bebdcb8c20b

Best regards,
-- 
Peng Fan <peng.fan@nxp.com>


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

* [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:52   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove Peng Fan
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

platform_irq_count() resolves every parent interrupt while counting the
channels. Resolving an interrupt creates a Linux IRQ mapping as a side
effect, so a probe failure before or during channel setup leaves
mappings behind for channels that were counted but never reached.

Count the interrupt entries with of_irq_count(), which does not create
mappings, and resolve each parent lazily with of_irq_get() in the channel
loop. of_irq_count() cannot return -EPROBE_DEFER, but of_irq_get() still
does when the parent interrupt domain is unavailable, so probe deferral
is preserved.

Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 73926dec52ab..7552a3d0c369 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -204,10 +204,8 @@ static int imx_intmux_probe(struct platform_device *pdev)
 	int channum;
 	int i, ret;
 
-	channum = platform_irq_count(pdev);
-	if (channum == -EPROBE_DEFER) {
-		return -EPROBE_DEFER;
-	} else if (channum > CHAN_MAX_NUM) {
+	channum = of_irq_count(np);
+	if (channum > CHAN_MAX_NUM) {
 		dev_err(&pdev->dev, "supports up to %d multiplex channels\n",
 			CHAN_MAX_NUM);
 		return -EINVAL;
@@ -244,10 +242,12 @@ static int imx_intmux_probe(struct platform_device *pdev)
 	for (i = 0; i < channum; i++) {
 		data->irqchip_data[i].chanidx = i;
 
-		data->irqchip_data[i].irq = irq_of_parse_and_map(np, i);
+		data->irqchip_data[i].irq = of_irq_get(np, i);
 		if (data->irqchip_data[i].irq <= 0) {
-			ret = -EINVAL;
-			dev_err(&pdev->dev, "failed to get irq\n");
+			ret = data->irqchip_data[i].irq;
+			if (!ret)
+				ret = -EINVAL;
+			dev_err_probe(&pdev->dev, ret, "failed to get irq\n");
 			goto out;
 		}
 

-- 
2.56.0


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

* [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
  2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:53   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path Peng Fan
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

The driver removes its IRQ domains without disposing the mappings
created for their 32 input lines, and it never releases the parent
IRQ mappings obtained with irq_of_parse_and_map(). Removing a domain
while mappings are still present leaves those descriptors pointing at
a freed domain, and the parent mappings leak on every unbind.

Mask the parent interrupt and wait for a handler that is already
running to finish before detaching it, then unchain it, dispose the
child mappings, remove the domain and release the parent mapping.

Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 7552a3d0c369..3b4eb9bd6678 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -296,10 +296,19 @@ 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_domain_remove(data->irqchip_data[i].domain);
+		irq_dispose_mapping(data->irqchip_data[i].irq);
 	}
 
 	pm_runtime_disable(&pdev->dev);

-- 
2.56.0


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

* [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
  2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
  2026-12-03  9:29 ` [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:50   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 4/8] irqchip/imx-intmux: Reject zero channel count Peng Fan
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

When setting up a channel fails after previous channels have been
initialized, the error path only disables the clock. The chained
handlers of those channels stay registered with handler data pointing
into the devres-managed intmux_data, which is released when probe
fails, leaving dangling pointers behind. The created IRQ domains and
parent IRQ mappings are leaked as well.

Unwind the initialized channels, tear down runtime PM and only then
disable the clock. Mask each parent interrupt and wait for a running
chained handler to finish before detaching it, so the rollback cannot
race with an in-flight imx_intmux_irq_handler().

Also enable the clock before touching runtime PM so that a clock
failure cannot leave runtime PM enabled with an unbalanced usage
counter, and propagate a pm_runtime_set_active() failure after
unwinding the usage count and clock reference.

Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 3b4eb9bd6678..06cf75a93373 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -229,16 +229,21 @@ static int imx_intmux_probe(struct platform_device *pdev)
 	data->channum = channum;
 	raw_spin_lock_init(&data->lock);
 
-	pm_runtime_get_noresume(&pdev->dev);
-	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
-
 	ret = clk_prepare_enable(data->ipg_clk);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to enable ipg clk: %d\n", ret);
 		return ret;
 	}
 
+	pm_runtime_get_noresume(&pdev->dev);
+	ret = pm_runtime_set_active(&pdev->dev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to set runtime PM active: %d\n", ret);
+		pm_runtime_put_noidle(&pdev->dev);
+		goto err_disable_clk;
+	}
+	pm_runtime_enable(&pdev->dev);
+
 	for (i = 0; i < channum; i++) {
 		data->irqchip_data[i].chanidx = i;
 
@@ -256,6 +261,7 @@ static int imx_intmux_probe(struct platform_device *pdev)
 		if (!domain) {
 			ret = -ENOMEM;
 			dev_err(&pdev->dev, "failed to create IRQ domain\n");
+			irq_dispose_mapping(data->irqchip_data[i].irq);
 			goto out;
 		}
 		data->irqchip_data[i].domain = domain;
@@ -279,6 +285,24 @@ 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_domain_remove(data->irqchip_data[i].domain);
+		irq_dispose_mapping(data->irqchip_data[i].irq);
+	}
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
+err_disable_clk:
 	clk_disable_unprepare(data->ipg_clk);
 	return ret;
 }

-- 
2.56.0


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

* [PATCH v2 4/8] irqchip/imx-intmux: Reject zero channel count
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
                   ` (2 preceding siblings ...)
  2026-12-03  9:29 ` [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:29 ` [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered Peng Fan
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

of_irq_count() returns the number of interrupt entries and never a
negative error. A node without interrupts yields zero, which passes the
upper-bound check and lets probe succeed without initializing a channel.
Reject a zero channel count.

Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 06cf75a93373..8eae3ed121c8 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -205,9 +205,9 @@ static int imx_intmux_probe(struct platform_device *pdev)
 	int i, ret;
 
 	channum = of_irq_count(np);
-	if (channum > CHAN_MAX_NUM) {
-		dev_err(&pdev->dev, "supports up to %d multiplex channels\n",
-			CHAN_MAX_NUM);
+	if (!channum || channum > CHAN_MAX_NUM) {
+		dev_err(&pdev->dev, "invalid number of channels: %d\n",
+			channum);
 		return -EINVAL;
 	}
 

-- 
2.56.0


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

* [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
                   ` (3 preceding siblings ...)
  2026-12-03  9:29 ` [PATCH v2 4/8] irqchip/imx-intmux: Reject zero channel count Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:40   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers Peng Fan
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

The child interrupts are handled by handle_level_irq() and xlate()
advertises IRQ_TYPE_LEVEL_HIGH, but the descriptors are not marked
IRQ_LEVEL. Apart from the inconsistency, the flag feeds IRQD_LEVEL,
which makes check_irq_resend() skip replaying level interrupts.

Set IRQ_LEVEL in the map callback.

Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 8eae3ed121c8..a9c554eba958 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -124,6 +124,7 @@ static int imx_intmux_irq_map(struct irq_domain *h, unsigned int irq,
 {
 	struct intmux_irqchip_data *data = h->host_data;
 
+	irq_set_status_flags(irq, IRQ_LEVEL);
 	irq_set_chip_data(irq, data);
 	irq_set_chip_and_handler(irq, &imx_intmux_irq_chip, handle_level_irq);
 

-- 
2.56.0


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

* [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
                   ` (4 preceding siblings ...)
  2026-12-03  9:29 ` [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:46   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear() Peng Fan
  2026-12-03  9:29 ` [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel() Peng Fan
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

The xlate callback validates the interrupt specifier cells, but uses
WARN_ON() for checks that can be triggered by user-supplied device tree
data. A malformed specifier is an expected, recoverable error, so the
WARN only floods the log.

Return -EINVAL without the splat. Also reject source numbers beyond the
32 inputs of a channel instead of letting the association hit the WARN
in irq_domain_associate_locked().

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index a9c554eba958..369132b4677b 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -145,10 +145,13 @@ static int imx_intmux_irq_xlate(struct irq_domain *d, struct device_node *node,
 	 * the 1st cell: hw interrupt number
 	 * the 2nd cell: channel index
 	 */
-	if (WARN_ON(intsize != 2))
+	if (intsize != 2)
 		return -EINVAL;
 
-	if (WARN_ON(intspec[1] >= data->channum))
+	if (intspec[0] >= 32)
+		return -EINVAL;
+
+	if (intspec[1] >= data->channum)
 		return -EINVAL;
 
 	*out_hwirq = intspec[0];

-- 
2.56.0


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

* [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear()
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
                   ` (5 preceding siblings ...)
  2026-12-03  9:29 ` [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03  9:55   ` sashiko-bot
  2026-12-03  9:29 ` [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel() Peng Fan
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

Manage the per-channel IRQ domains with devres so that they are removed
automatically when probe fails or the driver is unbound, instead of
calling irq_domain_remove() explicitly in the probe error path and in
imx_intmux_remove().

The child mappings are still disposed explicitly before the domains go
away. devres runs after imx_intmux_remove() and after the probe error
path returns, so each domain is removed with an empty reverse map once
the IPG clock is no longer in use. The clock has no managed disable
action.

No functional change.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/irqchip/irq-imx-intmux.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
index 369132b4677b..eeba45f312be 100644
--- a/drivers/irqchip/irq-imx-intmux.c
+++ b/drivers/irqchip/irq-imx-intmux.c
@@ -260,8 +260,9 @@ static int imx_intmux_probe(struct platform_device *pdev)
 			goto out;
 		}
 
-		domain = irq_domain_create_linear(of_fwnode_handle(np), 32, &imx_intmux_domain_ops,
-					       &data->irqchip_data[i]);
+		domain = devm_irq_domain_create_linear(&pdev->dev, dev_fwnode(&pdev->dev), 32,
+						       &imx_intmux_domain_ops,
+						       &data->irqchip_data[i]);
 		if (!domain) {
 			ret = -ENOMEM;
 			dev_err(&pdev->dev, "failed to create IRQ domain\n");
@@ -301,7 +302,6 @@ static int imx_intmux_probe(struct platform_device *pdev)
 		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
 			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
 							     hwirq));
-		irq_domain_remove(data->irqchip_data[i].domain);
 		irq_dispose_mapping(data->irqchip_data[i].irq);
 	}
 	pm_runtime_disable(&pdev->dev);
@@ -335,7 +335,6 @@ static void imx_intmux_remove(struct platform_device *pdev)
 		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
 			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
 							     hwirq));
-		irq_domain_remove(data->irqchip_data[i].domain);
 		irq_dispose_mapping(data->irqchip_data[i].irq);
 	}
 

-- 
2.56.0


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

* [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel()
  2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
                   ` (6 preceding siblings ...)
  2026-12-03  9:29 ` [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear() Peng Fan
@ 2026-12-03  9:29 ` Peng Fan
  2026-12-03 10:01   ` sashiko-bot
  7 siblings, 1 reply; 16+ messages in thread
From: Peng Fan @ 2026-12-03  9:29 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Frank Li, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Shengjiu Wang,
	Marc Zyngier
  Cc: linux-kernel, imx, linux-arm-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

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@nxp.com>
---
 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


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

* Re: [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered
  2026-12-03  9:29 ` [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered Peng Fan
@ 2026-12-03  9:40   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:40 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] irqchip/imx-intmux: commit log misattributes check_irq_resend()
  to IRQD_LEVEL
--

commit 7a64757a768c2c210172b6139603d2d7083d4d4c
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Mark input interrupts as level-triggered

This commit sets the IRQ_LEVEL status flag on mapped interrupts in
imx_intmux_irq_map().

> The child interrupts are handled by handle_level_irq() and xlate()
> advertises IRQ_TYPE_LEVEL_HIGH, but the descriptors are not marked
> IRQ_LEVEL. Apart from the inconsistency, the flag feeds IRQD_LEVEL,
> which makes check_irq_resend() skip replaying level interrupts.

[Severity: Low]
Is the commit message accurate about what check_irq_resend() inspects?

irq_modify_status() sets _IRQ_LEVEL in desc->status_use_accessors and
separately mirrors it into IRQD_LEVEL on desc->irq_data.
check_irq_resend() checks irq_settings_is_level(desc), which tests
_IRQ_LEVEL directly rather than IRQD_LEVEL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=5

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

* Re: [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers
  2026-12-03  9:29 ` [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers Peng Fan
@ 2026-12-03  9:46   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:46 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] irqchip/imx-intmux: missing Fixes trailer for commit
  2fbb13961e74
--

commit 14870f9b46fe1eda35fb46aa8429184e92a348d1
Author: Peng Fan <peng.fan@nxp.com>

> irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers
>
> The xlate callback validates the interrupt specifier cells, but uses
> WARN_ON() for checks that can be triggered by user-supplied device tree
> data. A malformed specifier is an expected, recoverable error, so the
> WARN only floods the log.
>
> Return -EINVAL without the splat. Also reject source numbers beyond the
> 32 inputs of a channel instead of letting the association hit the WARN
> in irq_domain_associate_locked().
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

[Severity: Low]
This fixes the xlate validation bugs introduced with the original driver.
Should this include:

  Fixes: 2fbb13961e74 ("irqchip: Add NXP INTMUX interrupt multiplexer support")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=6

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

* Re: [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path
  2026-12-03  9:29 ` [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path Peng Fan
@ 2026-12-03  9:50   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:50 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] irqchip/imx-intmux: lazy disable_irq() race in
  imx_intmux_probe() rollback
- [Low] irqchip/imx-intmux: missing CHANIER clear in imx_intmux_probe()
  rollback
--

commit 149da065195934513e17f562f9dd9bf36e9b88d8
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Fix probe error path

This commit unwinds initialized channels, tears down runtime PM, and
reorders clock enablement with runtime PM setup on the imx_intmux_probe()
error path.

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index 3b4eb9bd6678b..06cf75a93373b 100644
> --- a/drivers/irqchip/irq-imx-intmux.c
> +++ b/drivers/irqchip/irq-imx-intmux.c

[ ... ]

> @@ -279,6 +285,24 @@ 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);

[Severity: Medium]
Can disable_irq() leave the parent GICv3 SPI unmasked here and allow
imx_intmux_irq_handler() to race with the rollback?

Neither gic_chip nor gic_eoimode1_chip implements .irq_disable, and
IRQ_DISABLE_UNLAZY is not set on the parent SPI.  disable_irq() ->
__irq_disable(desc, false) therefore does a lazy disable and leaves the
interrupt unmasked in hardware when synchronize_irq() returns.

Because imx_intmux_irq_handler() is a chained handler, it does not check
irqd_irq_disabled() or set IRQD_IRQ_INPROGRESS.
irq_set_chained_handler_and_data() then clears handler_data before
__irq_do_set_handler() masks the IRQ, with no synchronize_irq() after:

CPU0                                CPU1
imx_intmux_probe()
  disable_irq(irq)
    __irq_disable(desc, false)
    /* GICv3 SPI stays unmasked */
    synchronize_irq(irq)
  irq_set_chained_handler_and_data()
    handler_data = NULL
                                    imx_intmux_irq_handler()
                                      d = irq_desc_get_handler_data(desc)
                                      d->chanidx  <-- NULL dereference
    __irq_do_set_handler()
      mask_ack_irq(desc)

If imx_intmux_irq_handler() reads handler_data just before it is cleared,
it can also keep running unsynchronized while the rollback removes the
domain, disables data->ipg_clk, and devres frees intmux_data, causing a
use-after-free or unclocked MMIO access.

Setting IRQ_DISABLE_UNLAZY before disable_irq(), or calling
irq_set_chained_handler(irq, NULL) followed by synchronize_irq(irq) before
clearing handler_data, would ensure the parent line is masked and drained
first.

> +		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
> +			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
> +							     hwirq));
> +		irq_domain_remove(data->irqchip_data[i].domain);
> +		irq_dispose_mapping(data->irqchip_data[i].irq);
> +	}

[Severity: Low]
Should this rollback loop also clear CHANIER(i) before tearing down each
channel, as imx_intmux_remove() does?

Because irq_domain_create_linear() publishes each channel domain before
later channels are set up, a concurrently probing consumer can map and
unmask a child IRQ on an earlier channel before a later channel fails.

irq_dispose_mapping() -> irq_domain_disassociate() installs no_irq_chip
before masking, so imx_intmux_irq_mask() is not called and those
CHANIER(i) enable bits stay set during rollback and after probe fails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=3

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

* Re: [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels
  2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
@ 2026-12-03  9:52   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:52 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] irqchip/imx-intmux: moving deferral to of_irq_get() leaks
  runtime PM state
--

commit 42b78989833d0bb58e9611bbf6a028b1d276be79
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Don't create parent mappings while counting channels

This commit replaces platform_irq_count() with of_irq_count() and uses
of_irq_get() inside the channel loop in imx_intmux_probe() so parent IRQ
mappings are not created while counting channels.

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index 73926dec52abf..7552a3d0c3695 100644
> --- a/drivers/irqchip/irq-imx-intmux.c
> +++ b/drivers/irqchip/irq-imx-intmux.c
> @@ -204,10 +204,8 @@ static int imx_intmux_probe(struct platform_device *pdev)
>  	int channum;
>  	int i, ret;
>  
> -	channum = platform_irq_count(pdev);
> -	if (channum == -EPROBE_DEFER) {
> -		return -EPROBE_DEFER;
> -	} else if (channum > CHAN_MAX_NUM) {
> +	channum = of_irq_count(np);
> +	if (channum > CHAN_MAX_NUM) {
>  		dev_err(&pdev->dev, "supports up to %d multiplex channels\n",
>  			CHAN_MAX_NUM);
>  		return -EINVAL;
> @@ -244,10 +242,12 @@ static int imx_intmux_probe(struct platform_device *pdev)
>  	for (i = 0; i < channum; i++) {
>  		data->irqchip_data[i].chanidx = i;
>  
> -		data->irqchip_data[i].irq = irq_of_parse_and_map(np, i);
> +		data->irqchip_data[i].irq = of_irq_get(np, i);
>  		if (data->irqchip_data[i].irq <= 0) {
> -			ret = -EINVAL;
> -			dev_err(&pdev->dev, "failed to get irq\n");
> +			ret = data->irqchip_data[i].irq;
> +			if (!ret)
> +				ret = -EINVAL;
> +			dev_err_probe(&pdev->dev, ret, "failed to get irq\n");
>  			goto out;
>  		}
>  

[Severity: Medium]
Does moving -EPROBE_DEFER from platform_irq_count() into of_irq_get() leak
runtime PM state when probe defers?

Previously, -EPROBE_DEFER returned before pm_runtime_get_noresume(),
pm_runtime_set_active(), and pm_runtime_enable() ran.  Now of_irq_get()
jumps to the out label, which only calls clk_disable_unprepare() and leaves
runtime PM enabled with usage_count set to 1.

Because runtime PM remains enabled, device_unbind_cleanup() ->
pm_runtime_reinit() returns early without resetting RPM_ACTIVE.  On the
retried probe, pm_runtime_enable() logs "Unbalanced pm_runtime_enable!" and
the extra usage_count permanently prevents runtime suspend.

If of_irq_get() defers on a channel after the first one, earlier channels
also stay registered with chained handlers pointing to devm-freed
intmux_data, causing a use-after-free.

This regression is fixed later in the series by commit "irqchip/imx-intmux:
Fix probe error path", so ordering that patch before this one would avoid
breaking bisection and standalone stable backports.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=1

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

* Re: [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove
  2026-12-03  9:29 ` [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove Peng Fan
@ 2026-12-03  9:53   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:53 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] irqchip/imx-intmux: lazy disable_irq() leaves race in
  imx_intmux_remove()
- [Medium] irqchip/imx-intmux: lazy disable_irq() leaves parent IRQ
  unmasked on remove
- [Low] irqchip/imx-intmux: commit message cites old
  irq_of_parse_and_map()
--

commit ba79cdc897e9950cf9db9d3877c7ec4b69f3800c
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Dispose IRQ mappings on remove

This commit masks and unchains each INTMUX channel's parent interrupt,
disposes the 32 child IRQ mappings before removing the channel domain,
and releases the parent IRQ mapping on driver removal.

> The driver removes its IRQ domains without disposing the mappings
> created for their 32 input lines, and it never releases the parent
> IRQ mappings obtained with irq_of_parse_and_map().

[Severity: Low]
Commit "irqchip/imx-intmux: Don't create parent mappings while counting
channels" already replaced irq_of_parse_and_map() with of_irq_get() in
imx_intmux_probe().  Should this refer to of_irq_get() instead?

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index 7552a3d0c3695..3b4eb9bd6678b 100644
> --- a/drivers/irqchip/irq-imx-intmux.c
> +++ b/drivers/irqchip/irq-imx-intmux.c
> @@ -296,10 +296,19 @@ 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_domain_remove(data->irqchip_data[i].domain);
> +		irq_dispose_mapping(data->irqchip_data[i].irq);

[Severity: Medium]
Can disable_irq() leave the parent GICv3 interrupt unmasked in hardware
and allow imx_intmux_irq_handler() to race with teardown?

On i.MX8 platforms using this driver, the parent controller is GICv3,
where neither gic_chip nor gic_eoimode1_chip implements .irq_disable.
Without IRQ_DISABLE_UNLAZY, disable_irq() calls __irq_disable(desc,
false), which only sets IRQD_IRQ_DISABLED in software and skips
mask_irq().

CPU0                              CPU1
imx_intmux_remove()
  disable_irq(irq)
    __irq_disable(desc, false)
    synchronize_irq(irq)
  irq_set_chained_handler_and_data(...)
    ...handler_data = NULL
                                  <hardirq>
                                  imx_intmux_irq_handler()
                                    irqchip_data = ...handler_data
                                    idx = irqchip_data->chanidx
                                      <-- NULL pointer dereference
    __irq_do_set_handler(..., NULL)

Because imx_intmux_irq_handler() is a chained handler, it runs without
desc->lock or checking irqd_irq_disabled().  If a parent SPI fires after
disable_irq() returns (for example when pm_runtime_resume_and_get()
fails so CHANIER(i) is not cleared, or while writel_relaxed(0, ...) is
still posted), CPU1 can dereference a NULL irqchip_data or continue
running against the freed irq_domain after irq_domain_remove().

irq_set_chained_handler_and_data(..., NULL, NULL) masks the parent line
only after clearing handler_data and does not synchronize afterward, and
the trailing irq_dispose_mapping() installs no_irq_chip before its
synchronize_irq(), losing the GIC active-state check.

Setting IRQ_DISABLE_UNLAZY on the parent IRQ before disable_irq() would
force __irq_disable() to mask the GICv3 line in hardware before
synchronize_irq() runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=2

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

* Re: [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear()
  2026-12-03  9:29 ` [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear() Peng Fan
@ 2026-12-03  9:55   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03  9:55 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] irqchip/imx-intmux: devm_irq_domain_create_linear() inverts
  clock/PM teardown
--

commit 7858358f254863ea504bc6fe05b47317cf04b64e
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Use devm_irq_domain_create_linear()

This commit switches per-channel IRQ domain creation to
devm_irq_domain_create_linear() and removes the explicit
irq_domain_remove() calls from the probe error path and
imx_intmux_remove().

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index 369132b4677ba..eeba45f312be9 100644
> --- a/drivers/irqchip/irq-imx-intmux.c
> +++ b/drivers/irqchip/irq-imx-intmux.c
> @@ -260,8 +260,9 @@ static int imx_intmux_probe(struct platform_device *pdev)
>  			goto out;
>  		}
>  
> -		domain = irq_domain_create_linear(of_fwnode_handle(np), 32, &imx_intmux_domain_ops,
> -					       &data->irqchip_data[i]);
> +		domain = devm_irq_domain_create_linear(&pdev->dev, dev_fwnode(&pdev->dev), 32,
> +						       &imx_intmux_domain_ops,
> +						       &data->irqchip_data[i]);
>  		if (!domain) {
>  			ret = -ENOMEM;
>  			dev_err(&pdev->dev, "failed to create IRQ domain\n");
> @@ -301,7 +302,6 @@ static int imx_intmux_probe(struct platform_device *pdev)
>  		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
>  			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
>  							     hwirq));
> -		irq_domain_remove(data->irqchip_data[i].domain);
>  		irq_dispose_mapping(data->irqchip_data[i].irq);
>  	}
>  	pm_runtime_disable(&pdev->dev);
> @@ -335,7 +335,6 @@ static void imx_intmux_remove(struct platform_device *pdev)
>  		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
>  			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
>  							     hwirq));
> -		irq_domain_remove(data->irqchip_data[i].domain);
>  		irq_dispose_mapping(data->irqchip_data[i].irq);
>  	}
>  

[Severity: Medium]
Can deferring irq_domain_remove() to devres leave the channel IRQ domains
published after child mappings, runtime PM, and ipg_clk have already been
torn down?

Both the probe error path and imx_intmux_remove() dispose child mappings,
call pm_runtime_disable(), and call clk_disable_unprepare(data->ipg_clk)
before returning to the driver core.  The channel domains stay on
irq_domain_list until device_unbind_cleanup() runs devres_release_all().

When fw_devlink=off or fw_devlink=permissive is in effect, a consumer can
resolve an interrupt in that window after the disposal loop has finished:

CPU0                                CPU1
imx_intmux_remove()
  irq_dispose_mapping(...)
  pm_runtime_disable()
  clk_disable_unprepare(ipg_clk)
                                    of_irq_get()
                                      irq_create_of_mapping()
device_unbind_cleanup()
  devres_release_all()
    irq_domain_remove(domain)
    kfree(data)
                                    request_irq()
                                      ...
                                        imx_intmux_irq_unmask()
                                        <-- use-after-free

irq_domain_remove() frees the domain without disposing entries in the
linear revmap array, and devres then frees data, leaving the new irq_desc
with dangling domain and chip_data pointers.

If CONFIG_PM is disabled, irq_chip_pm_get() also returns 0, allowing a
concurrent request_irq() in that window to call imx_intmux_irq_unmask()
and access CHANIER(idx) after ipg_clk has been disabled.

Either keeping explicit irq_domain_remove() before pm_runtime_disable()
and clk_disable_unprepare(), or managing ipg_clk and runtime PM via devres
registered before devm_irq_domain_create_linear() (as irq-imx-irqsteer.c
does), would preserve reverse teardown order.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=7

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

* Re: [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel()
  2026-12-03  9:29 ` [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel() Peng Fan
@ 2026-12-03 10:01   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-03 10:01 UTC (permalink / raw)
  To: Peng Fan; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] irqchip/imx-intmux: lazy disable_irq() races with handler
  teardown
--

commit 58ddadbb56d0e9d72dc72cc109e6fc29fd9722be
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Factor out imx_intmux_teardown_channel()

This commit factors the per-channel teardown sequence out of the probe
error path and imx_intmux_remove() into imx_intmux_teardown_channel().

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index eeba45f312be9..cce21ac8c21d5 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);
> +}
> +

[Severity: Medium]
Can disable_irq() leave the parent GIC SPI unmasked in hardware and let
imx_intmux_irq_handler() race with irq_set_chained_handler_and_data()?

On GICv3, neither gic_chip nor gic_eoimode1_chip implements .irq_disable,
and IRQ_DISABLE_UNLAZY is not set on the parent SPI.  disable_irq()
therefore calls __irq_disable(desc, false), which only sets
IRQD_IRQ_DISABLED in software and skips mask_irq().

Unlike standard flow handlers, imx_intmux_irq_handler() runs without
checking irqd_irq_disabled() or setting IRQD_IRQ_INPROGRESS.  Because
irq_set_chained_handler_and_data() clears handler_data before masking the
parent IRQ, a racing interrupt on another CPU can dereference NULL:

CPU0                                 CPU1
imx_intmux_teardown_channel()
  disable_irq(irq)
    __irq_disable(desc, false)
    /* SPI still unmasked */
  irq_set_chained_handler_and_data(
      irq, NULL, NULL)
    desc->...handler_data = NULL
                                     <hardirq>
                                     imx_intmux_irq_handler(desc)
                                       irqchip_data = NULL
                                       irqchip_data->chanidx
                                         <-- NULL pointer dereference
    __irq_do_set_handler(..., NULL)
      mask_ack_irq(desc)

If imx_intmux_irq_handler() reads handler_data just before it is cleared,
irq_dispose_mapping() installs no_irq_chip before synchronize_irq(), losing
the GIC active-state check so teardown can disable ipg_clk and free
intmux_data while the handler is still running.

Setting IRQ_DISABLE_UNLAZY on the parent IRQ before calling disable_irq()
would ensure the parent SPI is masked in hardware before synchronize_irq()
runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=8

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

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

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
2026-12-03  9:52   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove Peng Fan
2026-12-03  9:53   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path Peng Fan
2026-12-03  9:50   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 4/8] irqchip/imx-intmux: Reject zero channel count Peng Fan
2026-12-03  9:29 ` [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered Peng Fan
2026-12-03  9:40   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers Peng Fan
2026-12-03  9:46   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear() Peng Fan
2026-12-03  9:55   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel() Peng Fan
2026-12-03 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