Skip to contentSkip to conversation

soc: fsl: dpio: Fix IRQ cleanup during probe and removal

PATCH Applied Myeonghun Pak 3 participants 5 messages Oct 2 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover soc: fsl: dpio: Fix IRQ cleanup during probe and removal

This series fixes two DPIO I/O object lifetime issues during probe failure and device removal.

Patch 1 releases the I/O object when IRQ registration fails and removes the unnecessary unregister call from the probe error path. Patch 2 frees the managed IRQ before returning its resource to the MC pool and before releasing the I/O object during removal.

Both patches carry their respective Fixes tags and are marked for stable backporting. Patch 2 is based on patch 1, which removes the probe error path call to unregister_dpio_irq_handlers() before that helper starts freeing the managed IRQ.

Changes in v2:
- Present the two previously separate patches as a series.
- Remove the unnecessary unregister call from the probe error path, as suggested by Ioana Ciornei.
- Move devm_free_irq() into unregister_dpio_irq_handlers(), as suggested by Ioana Ciornei, to keep registration and unregistration in sync.
- Add Cc: [email protected] to both patches.

Based on Linux 7.3-rc3 (fd73f4a6659897191fa0d40695fe370925dd3780).

Myeonghun Pak (2):
soc: fsl: dpio: Fix cleanup on IRQ registration failure
soc: fsl: dpio: Free the IRQ before releasing the I/O object

 drivers/soc/fsl/dpio/dpio-driver.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 soc: fsl: dpio: Fix cleanup on IRQ registration failure

IRQ registration happens after dpaa2_io_create(), but its failure path only releases the IRQ resources and the MC portal. The I/O object stays allocated and published in the service list and per-CPU lookup table, while devres unmaps its portal registers after probe fails.

Call dpaa2_io_down() on IRQ registration failure to remove the object from those lookup structures and free it. Reorder the error labels so that a failed dpaa2_io_create() still skips this cleanup.

Remove unregister_dpio_irq_handlers() from the probe error path, since no IRQ handler or affinity hint has been installed when registration fails.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes fe8fe7723a3a ("soc: fsl: dpio: register dpio irq handlers after dpio create")
Assisted-by LLM

---
Changes in v2:
- Remove the unnecessary unregister_dpio_irq_handlers() call from the probe error path, as suggested by Ioana Ciornei.
- Include this fix as patch 1 of the two-patch DPIO cleanup series.
- Add Cc: [email protected].

 drivers/soc/fsl/dpio/dpio-driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/fsl/dpio/dpio-driver.c +2 -2
index d5198ff..8d31346 100644
@@ -244,9 +244,9 @@ static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
 
 	return 0;
 
-err_dpaa2_io_create:
-	unregister_dpio_irq_handlers(dpio_dev);
 err_register_dpio_irq:
+	dpaa2_io_down(priv->io);
+err_dpaa2_io_create:
 	fsl_mc_free_irqs(dpio_dev);
 err_allocate_irqs:
 	dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/2 soc: fsl: dpio: Free the IRQ before releasing the I/O object

In reply to Myeonghun Pak

The DPIO interrupt handler accesses priv->io, but dpaa2_dpio_remove() releases that object before tearing down the interrupts. The IRQ was requested with devm_request_irq(), and unregister_dpio_irq_handlers() only clears its affinity hint. fsl_mc_free_irqs() returns IRQ resources to the MC resource pool without freeing the handler. An interrupt can therefore access the freed I/O object before devres releases the IRQ.

Explicitly free the managed IRQ in unregister_dpio_irq_handlers() before returning its resource to the pool, and perform IRQ teardown before releasing the I/O object. This also waits for an in-flight handler while the object is still valid.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 993fec7e11ca ("bus: fsl-mc: dpio: add the DPAA2 DPIO object driver")
Assisted-by LLM

---
Changes in v2:
- Move devm_free_irq() into unregister_dpio_irq_handlers(), as suggested by Ioana Ciornei, to keep IRQ registration and unregistration in sync.
- Base this patch on the probe cleanup fix in patch 1, which removes the unregister call from the probe error path.
- Add Cc: [email protected].

 drivers/soc/fsl/dpio/dpio-driver.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/soc/fsl/dpio/dpio-driver.c +3 -2
index 8d31346..d8f28fb 100644
@@ -88,6 +88,7 @@ static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev)
 
 	/* clear the affinity hint */
 	irq_set_affinity_hint(irq->virq, NULL);
+	devm_free_irq(&dpio_dev->dev, irq->virq, &dpio_dev->dev);
 }
 
 static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu)
@@ -276,10 +277,10 @@ static void dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
 	priv = dev_get_drvdata(dev);
 	cpu = dpaa2_io_get_cpu(priv->io);
 
-	dpaa2_io_down(priv->io);
-
 	dpio_teardown_irqs(dpio_dev);
 
+	dpaa2_io_down(priv->io);
+
 	cpumask_set_cpu(cpu, cpus_unused_mask);
 
 	err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
Signature · 1 line
2.53.0
maintainer Reviewed-by on the v2 series
#3 lore raw
In reply to Myeonghun Pak
Quoted 8 lines · Myeonghun Pak

This series fixes two DPIO I/O object lifetime issues during probe failure and device removal.

Patch 1 releases the I/O object when IRQ registration fails and removes the unnecessary unregister call from the probe error path. Patch 2 frees the managed IRQ before returning its resource to the MC pool and before releasing the I/O object during removal.

Quoted 5 lines

Both patches carry their respective Fixes tags and are marked for stable backporting. Patch 2 is based on patch 1, which removes the probe error path call to unregister_dpio_irq_handlers() before that helper starts freeing the managed IRQ.

Thanks!

maintainer Applied
#4 lore raw
In reply to Myeonghun Pak
Quoted 9 lines · Myeonghun Pak

This series fixes two DPIO I/O object lifetime issues during probe failure and device removal.

Patch 1 releases the I/O object when IRQ registration fails and removes the unnecessary unregister call from the probe error path. Patch 2 frees the managed IRQ before returning its resource to the MC pool and before releasing the I/O object during removal.

[...]

Applied, thanks!

[1/2] soc: fsl: dpio: Fix cleanup on IRQ registration failure

      commit: 899559907f9d8bce0720f6d4336b2871e83957ae
[2/2] soc: fsl: dpio: Free the IRQ before releasing the I/O object
      commit: c4ddf1eb1d321e40d82fb89d34b61edb3f927198

Best regards,

Signature · 1 line
Christophe Leroy (CS GROUP) <[email protected]>