irqchip/imx-irqsteer: Convert to devm_pm_runtime_enable()
Subsystems (2)
Fabio Estevam
reviewerPATCH v4 1/2 irqchip/imx-irqsteer: Convert to devm_pm_runtime_enable()
From: Fabio Estevam <[email protected]>
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.
The driver core may runtime suspend the device before calling remove. In that case, the runtime suspend callback has already disabled the IPG clock, so only disable it in remove when the device is still active.
Set up runtime PM before creating the IRQ domain and registering chained handlers so that a failure cannot leave either resource pointing at freed driver data.
---
Changes since v3:
- Do not disable the IPG clock in remove when runtime PM has already suspended the device, preventing a clock reference-count underflow. (Radu)
drivers/irqchip/irq-imx-irqsteer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/irqchip/irq-imx-irqsteer.c +7 -4
@@ -236,6 +236,11 @@ static int imx_irqsteer_probe(struct platform_device *pdev)if (irqsteer_has_chanctrl (data->devtype_data))writel_relaxed (BIT (data->channel), data->regs +CHANCTRL ); +pm_runtime_set_active (&pdev->dev); + ret =devm_pm_runtime_enable (&pdev->dev); +if (ret) + goto out; + data->domain =irq_domain_create_linear (dev_fwnode (&pdev->dev), data->reg_num *32 , &imx_irqsteer_domain_ops, data);if (!data->domain) {
@@ -262,9 +267,6 @@ 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); -return 0 ; out:clk_disable_unprepare (data->ipg_clk);
@@ -286,7 +288,8 @@ static void imx_irqsteer_remove(struct platform_device *pdev)irq_domain_remove (irqsteer_data->domain); -clk_disable_unprepare (irqsteer_data->ipg_clk); +if (!pm_runtime_status_suspended (&pdev->dev)) +clk_disable_unprepare (irqsteer_data->ipg_clk); }#ifdef CONFIG_PM
Signature · 1 line
2.43.0
Fabio Estevam
reviewerPATCH v4 2/2 irqchip/imx-irqsteer: Validate IRQ count before creating domain
From: Fabio Estevam <[email protected]>
The IRQ count is validated after creating the IRQ domain. If it is invalid, probe returns without removing the domain, leaving its host data pointing at devm-managed memory that is freed on probe failure.
Validate the count before allocating resources to avoid the leak and dangling pointer.
---
Changes since v3:
- None.
drivers/irqchip/irq-imx-irqsteer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/irqchip/irq-imx-irqsteer.c +2 -5
@@ -217,6 +217,8 @@ static int imx_irqsteer_probe(struct platform_device *pdev)*/ data->irq_count =DIV_ROUND_UP (irqs_num,64 ); data->reg_num = irqs_num /32 ; +if (!data->irq_count || data->irq_count >CHAN_MAX_OUTPUT_INT ) +return -EINVAL ;if (IS_ENABLED (CONFIG_PM )) { data->saved_reg = devm_kzalloc(&pdev->dev,
@@ -250,11 +252,6 @@ static int imx_irqsteer_probe(struct platform_device *pdev) }irq_domain_set_pm_device (data->domain, &pdev->dev); -if (!data->irq_count || data->irq_count >CHAN_MAX_OUTPUT_INT ) { - ret = -EINVAL ; - goto out; - } -for (i =0 ; i < data->irq_count; i++) { data->irq[i] =irq_of_parse_and_map (np, i);if (!data->irq[i])
Signature · 1 line
2.43.0
Re: [PATCH v4 2/2] irqchip/imx-irqsteer: Validate IRQ count before creating domain
Quoted 6 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
The IRQ count is validated after creating the IRQ domain. If it is invalid, probe returns without removing the domain, leaving its host data pointing at devm-managed memory that is freed on probe failure.
Quoted 6 lines
Validate the count before allocating resources to avoid the leak and dangling pointer.
Fixes 28528fca4908 ("irqchip/imx-irqsteer: Add multi output interrupts support")Signed-off-by Fabio Estevam <[email protected]>---
Sorry, I missed this patch.
Quoted 34 lines
Changes since v3:
- None.drivers/irqchip/irq-imx-irqsteer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/irqchip/irq-imx-irqsteer.c +2
-6@@ -217,6 +217,8 @@ static int imx_irqsteer_probe(struct platform_device *pdev)*/ data->irq_count =DIV_ROUND_UP (irqs_num,64 ); data->reg_num = irqs_num /32 ; +if (!data->irq_count || data->irq_count >CHAN_MAX_OUTPUT_INT ) +return -EINVAL ;if (IS_ENABLED (CONFIG_PM )) { data->saved_reg = devm_kzalloc(&pdev->dev,@@ -250,11 +252,6 @@ static int imx_irqsteer_probe(struct platform_device *pdev) }irq_domain_set_pm_device (data->domain, &pdev->dev); -if (!data->irq_count || data->irq_count >CHAN_MAX_OUTPUT_INT ) { - ret = -EINVAL ; - goto out; - } -for (i =0 ; i < data->irq_count; i++) { data->irq[i] =irq_of_parse_and_map (np, i);if (!data->irq[i]) --2.43.0
Quoted 34 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
imx_irqsteer_probe()enables runtime PM, butimx_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.The driver core may runtime suspend the device before calling remove. In that case, the runtime suspend callback has already disabled the IPG clock, so only disable it in remove when the device is still active.
Set up runtime PM before creating the IRQ domain and registering chained handlers so that a failure cannot leave either resource pointing at freed driver data.
Fixes 4730d2233311 ("irqchip/imx-irqsteer: Add runtime PM support")Signed-off-by Fabio Estevam <[email protected]>---
Changes since v3:
- Do not disable the IPG clock in remove when runtime PM has already suspended the device, preventing a clock reference-count underflow. (Radu)drivers/irqchip/irq-imx-irqsteer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/irqchip/irq-imx-irqsteer.c +0
-0
drivers/irqchip/irq-imx-irqsteer.c static int imx_irqsteer_probe(struct platform_device *pdev) · line 240
Quoted 5 lines
drivers/irqchip/irq-imx-irqsteer.c +2
-0@@ -236,6 +236,11 @@ static int imx_irqsteer_probe(struct platform_device *pdev)if (irqsteer_has_chanctrl (data->devtype_data))writel_relaxed (BIT (data->channel), data->regs +CHANCTRL ); +pm_runtime_set_active (&pdev->dev); + ret =devm_pm_runtime_enable (&pdev->dev);
devm_pm_runtime_active_enable() do both work by one call.
Frank
Quoted 29 lines
drivers/irqchip/irq-imx-irqsteer.c +5
-5+if (ret) + goto out; + data->domain =irq_domain_create_linear (dev_fwnode (&pdev->dev), data->reg_num *32 , &imx_irqsteer_domain_ops, data);if (!data->domain) {@@ -262,9 +267,6 @@ 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); -return 0 ; out:clk_disable_unprepare (data->ipg_clk);@@ -286,7 +288,8 @@ static void imx_irqsteer_remove(struct platform_device *pdev)irq_domain_remove (irqsteer_data->domain); -clk_disable_unprepare (irqsteer_data->ipg_clk); +if (!pm_runtime_status_suspended (&pdev->dev)) +clk_disable_unprepare (irqsteer_data->ipg_clk); }#ifdef CONFIG_PM --2.43.0