Skip to contentSkip to conversation

irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable()

PATCH Superseded Fabio Estevam 4 participants 8 messages Jul 29 – Aug 5

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/1 irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable()

imx_irqsteer_probe() enables runtime PM, but imx_irqsteer_remove() does not disable it.

Consequently, runtime PM remains enabled after unbinding the device, and rebinding it triggers:

Unbalanced pm_runtime_enable!

Use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed.

Fixes 4730d2233311 ("irqchip/imx-irqsteer: Add runtime PM support")

---
Changes since v1:
- Use devm_pm_runtime_enable() (Frank)

 drivers/irqchip/irq-imx-irqsteer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-imx-irqsteer.c +3 -1
index 87b07f517be3..ba1203d3edd4 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, data);
 
 	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;
 
 	return 0;
 out:
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Adding devm_pm_runtime_enable() introduces a failure path that fails to deregister chained IRQ handlers, leading to a Use-After-Free.

Pre-existing issues:
- [High] The irq_domain created during probe is leaked and left registered on error paths, creating a dangling pointer risk. --

--- Patch [1]: [PATCH v2] irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable() --- commit 3959004c7e2715ec92cba0eb90ac30fdaf1b65c2
Author: Fabio Estevam <[email protected]>
Subject: irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable()

This commit converts the driver to use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed, fixing an unbalanced pm_runtime_enable warning.

drivers/irqchip/irq-imx-irqsteer.c static int imx_irqsteer_probe(struct platform_device *pdev) · line 268

Quoted 12 lines
drivers/irqchip/irq-imx-irqsteer.c +3 -1
index 87b07f517be35..ba1203d3edd4d 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, data);
 
 	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;

[Severity: High]
If devm_pm_runtime_enable() fails, does this new error path leave the chained IRQ handlers registered?

Earlier in imx_irqsteer_probe(), we register the chained handlers:

    for (i = 0; i < data->irq_count; i++) {
        ...
        irq_set_chained_handler_and_data(data->irq[i],
                                         imx_irqsteer_irq_handler,
                                         data);
    }

When we jump to the "out" label on failure, devres will free the "data" structure. If a parent IRQ fires after this, could imx_irqsteer_irq_handler() dereference the freed pointer?

drivers/irqchip/irq-imx-irqsteer.c static int imx_irqsteer_probe(struct platform_device *pdev) · line 271

Quoted 3 lines
drivers/irqchip/irq-imx-irqsteer.c +0 -0
 	return 0;
 out:

[Severity: High]
This is a pre-existing issue, but does this error path also leak the IRQ domain?

Earlier in probe, the domain is created:

    data->domain = irq_domain_create_linear(dev_fwnode(&pdev->dev), ...

The "out" label only disables the IPG clock, but doesn't call irq_domain_remove(). Is it possible that the IRQ domain is left registered in the system with its host_data pointing to the freed "data" structure, leading to a use-after-free if IRQ mappings are attempted later?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 25 lines · On Wed, Jul 29, 2026 at 10:22:45PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Adding devm_pm_runtime_enable() introduces a failure path that fails to deregister chained IRQ handlers, leading to a Use-After-Free.

Pre-existing issues:
- [High] The irq_domain created during probe is leaked and left registered on error paths, creating a dangling pointer risk. --

--- Patch [1]: [PATCH v2] irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable() --- commit 3959004c7e2715ec92cba0eb90ac30fdaf1b65c2
Author: Fabio Estevam <[email protected]>
Subject: irqchip: imx-irqsteer: Convert to devm_pm_runtime_enable()

This commit converts the driver to use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed, fixing an unbalanced pm_runtime_enable warning.

Quoted 7 lines
drivers/irqchip/irq-imx-irqsteer.c +0 -0
index 87b07f517be35..ba1203d3edd4d 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, data);
 
Quoted 9 lines

drivers/irqchip/irq-imx-irqsteer.c static int imx_irqsteer_probe(struct platform_device *pdev) · line 268

Quoted 5 lines
drivers/irqchip/irq-imx-irqsteer.c +3 -1
 	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;

[Severity: High]
If devm_pm_runtime_enable() fails, does this new error path leave the chained IRQ handlers registered?

I think move this before irq_domain_create_linear() and use devm_pm_runtime_set_active_enabled() should fix this problem

Frank

Quoted 33 lines

Earlier in imx_irqsteer_probe(), we register the chained handlers:

    for (i = 0; i < data->irq_count; i++) {
        ...
        irq_set_chained_handler_and_data(data->irq[i],
                                         imx_irqsteer_irq_handler,
                                         data);
    }

When we jump to the "out" label on failure, devres will free the "data" structure. If a parent IRQ fires after this, could imx_irqsteer_irq_handler() dereference the freed pointer?

drivers/irqchip/irq-imx-irqsteer.c static int imx_irqsteer_probe(struct platform_device *pdev) · line 271

Quoted 3 lines
drivers/irqchip/irq-imx-irqsteer.c +0 -0
 	return 0;
 out:

[Severity: High]
This is a pre-existing issue, but does this error path also leak the IRQ domain?

Earlier in probe, the domain is created:

    data->domain = irq_domain_create_linear(dev_fwnode(&pdev->dev), ...

The "out" label only disables the IPG clock, but doesn't call irq_domain_remove(). Is it possible that the IRQ domain is left registered in the system with its host_data pointing to the freed "data" structure, leading to a use-after-free if IRQ mappings are attempted later?

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

reviewer Reviewed-by on v2 1/1
#3 lore raw
In reply to Fabio Estevam
Quoted 32 lines · Fabio Estevam

imx_irqsteer_probe() enables runtime PM, but imx_irqsteer_remove() does not disable it.

Consequently, runtime PM remains enabled after unbinding the device, and rebinding it triggers:

Unbalanced pm_runtime_enable!

Use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed.

Fixes 4730d2233311 ("irqchip/imx-irqsteer: Add runtime PM support")

---
Changes since v1:
- Use devm_pm_runtime_enable() (Frank)

 drivers/irqchip/irq-imx-irqsteer.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-imx-irqsteer.c +0 -0
index 87b07f517be3..ba1203d3edd4 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
  	platform_set_drvdata(pdev, data);


  pm_runtime_set_active(&pdev->dev);

drivers/irqchip/irq-imx-irqsteer.c +3 -1
-	pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;
Quoted 3 lines


  return 0;
 out:

reviewer
#4 lore raw
Quoted 30 lines · Radu Rendec
Quoted 29 lines · Fabio Estevam

imx_irqsteer_probe() enables runtime PM, but imx_irqsteer_remove() does not disable it.

Consequently, runtime PM remains enabled after unbinding the device, and rebinding it triggers:

Unbalanced pm_runtime_enable!

Use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed.

Fixes 4730d2233311 ("irqchip/imx-irqsteer: Add runtime PM support")

---
Changes since v1:
- Use devm_pm_runtime_enable() (Frank)

 drivers/irqchip/irq-imx-irqsteer.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-imx-irqsteer.c +0 -0
index 87b07f517be3..ba1203d3edd4 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
  	platform_set_drvdata(pdev, data);


  pm_runtime_set_active(&pdev->dev);

drivers/irqchip/irq-imx-irqsteer.c +0 -1
-	pm_runtime_enable(&pdev->dev);
Quoted 8 lines
Quoted 6 lines
drivers/irqchip/irq-imx-irqsteer.c +3 -0
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;


  return 0;
 out:

I take that back. At a closer look, I think both issues identified by Sashiko are valid. While the second issue is marked as "pre-existing", the proposed patch introduces a new path where the issue can occur (leaking the irq domain).

While at it, I would also fix the existing issue that the bot identified, where the domain is leaked on this path:

        if (!data->irq_count || data->irq_count > CHAN_MAX_OUTPUT_INT) {
                ret = -EINVAL;
                goto out;
        }
author reviewer
#5 lore raw
Quoted 4 lines · Radu Rendec

I take that back. At a closer look, I think both issues identified by Sashiko are valid. While the second issue is marked as "pre-existing", the proposed patch introduces a new path where the issue can occur (leaking the irq domain).

Would the first version of the patch be acceptable?

reviewer
#6 lore raw
Quoted 8 lines · Fabio Estevam
Quoted 4 lines · Radu Rendec

I take that back. At a closer look, I think both issues identified by Sashiko are valid. While the second issue is marked as "pre-existing", the proposed patch introduces a new path where the issue can occur (leaking the irq domain).

Would the first version of the patch be acceptable?

It certainly avoids the problem of the extra error path that devm_pm_runtime_enable() introduces.

But Sashiko had a comment on the first version too, and I think at least the first issue - about the double-disable of the clock (if the device is suspended when it's removed) - is real.

In my (very limited) understanding of the runtime_pm framework, there are two ways to handle this cleanly:
* Manage the activation and deactivation of the clock indirectly through suspend/resume requests. The driver already enables the clock in its resume callback and disables the clock in its suspend callback. Instead of enabling/disabling the clock explicitly in the probe/remove function, use pm_runtime_get_sync() and pm_runtime_put(), which indirectly resume and respectively suspend the device. This is what drivers/irqchip/irq-renesas-intc-irqpin.c does (except it doesn't manage a clock).
* Call pm_runtime_get_sync() at the beginning of the remove function (which requires a matching pm_runtime_put() in the probe function). That will indirectly resume the device first, then it's safe to disable the clock.

At a high level, the second option above would like this:

static int imx_irqsteer_probe(struct platform_device *pdev) {
/* Initial setup / clock enablement */

pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev);
/* Mark device idle so it can autosuspend when unused */ pm_runtime_put_autosuspend(&pdev->dev);

return 0;
}

static void imx_irqsteer_remove(struct platform_device *pdev)

{
    pm_runtime_get_sync(&pdev->dev);
    pm_runtime_disable(&pdev->dev);

    /* Final clean up and disable clock */
}

That's closer to what the driver already does. But the part that I don't like is that the pm_runtime_put_autosuspend() call may suspend the device immediately, and I don't fully understand the implications of that.

Reviewed-by on v2 1/1
#7 lore raw
In reply to Fabio Estevam
Quoted 6 lines · Fabio Estevam

imx_irqsteer_probe() enables runtime PM, but imx_irqsteer_remove() does not disable it.

Consequently, runtime PM remains enabled after unbinding the device, and rebinding it triggers:

Quoted 8 lines

Unbalanced pm_runtime_enable!

Use devm_pm_runtime_enable() to automatically disable runtime PM when the device is removed.

Fixes 4730d2233311 ("irqchip/imx-irqsteer: Add runtime PM support")

---

Quoted 25 lines

Changes since v1:
- Use devm_pm_runtime_enable() (Frank)

 drivers/irqchip/irq-imx-irqsteer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/irqchip/irq-imx-irqsteer.c +3 -2
index 87b07f517be3..ba1203d3edd4 100644
@@ -263,7 +263,9 @@ static int imx_irqsteer_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, data);
 
 	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		goto out;
 
 	return 0;
 out:
--

2.43.0