pwm: tegra: Disable runtime PM on cleanup errors
Subsystems (4)
PATCH 1/1 pwm: tegra: Disable runtime PM on cleanup errors
tegra_pwm_probe() enables runtime PM before requesting the initial resume. If pm_runtime_resume_and_get() fails, probe returns with runtime PM still enabled as the managed driver resources are released.
The later probe unwind and remove paths use pm_runtime_force_suspend(), which disables runtime PM on success but enables it again if the suspend callback fails. Ignoring that error can therefore also leave runtime PM enabled during resource cleanup.
Disable runtime PM on the initial resume failure and when force-suspend fails. Do not disable it a second time after successful force-suspend, and preserve the original probe error. The failed resume_and_get call has already balanced its usage count, so it needs no additional put.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/pwm/pwm-tegra.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pwm/pwm-tegra.c +7 -3
@@ -346,8 +346,10 @@ static int tegra_pwm_probe(struct platform_device *pdev)pm_runtime_enable (&pdev->dev); ret =pm_runtime_resume_and_get (&pdev->dev); -if (ret) +if (ret) { +pm_runtime_disable (&pdev->dev);return ret; + }/* Set maximum frequency of the IP */ ret =dev_pm_opp_set_rate (&pdev->dev,ULONG_MAX );
@@ -395,7 +397,8 @@ static int tegra_pwm_probe(struct platform_device *pdev)return 0 ; put_pm:pm_runtime_put_sync_suspend (&pdev->dev); -pm_runtime_force_suspend (&pdev->dev); +if (pm_runtime_force_suspend (&pdev->dev)) +pm_runtime_disable (&pdev->dev);return ret; }
@@ -408,7 +411,8 @@ static void tegra_pwm_remove(struct platform_device *pdev)reset_control_assert (pc->rst); -pm_runtime_force_suspend (&pdev->dev); +if (pm_runtime_force_suspend (&pdev->dev)) +pm_runtime_disable (&pdev->dev); }static int __maybe_unused tegra_pwm_runtime_suspend (struct device *dev)
Quoted 55 lines · Myeonghun Pak
tegra_pwm_probe()enables runtime PM before requesting the initial resume. Ifpm_runtime_resume_and_get()fails, probe returns with runtime PM still enabled as the managed driver resources are released.The later probe unwind and remove paths use
pm_runtime_force_suspend(), which disables runtime PM on success but enables it again if the suspend callback fails. Ignoring that error can therefore also leave runtime PM enabled during resource cleanup.Disable runtime PM on the initial resume failure and when force-suspend fails. Do not disable it a second time after successful force-suspend, and preserve the original probe error. The failed
resume_and_getcall has already balanced its usage count, so it needs no additional put.This issue was identified during our ongoing static-analysis research while reviewing kernel code.
Fixes 3da9b0feaa16 ("pwm: tegra: Add runtime PM and OPP support")Assisted-by OpenAI:GPT-5.6Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- drivers/pwm/pwm-tegra.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/pwm/pwm-tegra.c +5
-2@@ -346,8 +346,10 @@ static int tegra_pwm_probe(struct platform_device *pdev)pm_runtime_enable (&pdev->dev); ret =pm_runtime_resume_and_get (&pdev->dev); -if (ret) +if (ret) { +pm_runtime_disable (&pdev->dev);return ret; + }/* Set maximum frequency of the IP */ ret =dev_pm_opp_set_rate (&pdev->dev,ULONG_MAX );@@ -395,7 +397,8 @@ static int tegra_pwm_probe(struct platform_device *pdev)return 0 ; put_pm:pm_runtime_put_sync_suspend (&pdev->dev); -pm_runtime_force_suspend (&pdev->dev); +if (pm_runtime_force_suspend (&pdev->dev)) +pm_runtime_disable (&pdev->dev);return ret; }
drivers/pwm/pwm-tegra.c static void tegra_pwm_remove(struct platform_device *pdev) · line 418
Quoted 9 lines
drivers/pwm/pwm-tegra.c +2
-1@@ -408,7 +411,8 @@ static void tegra_pwm_remove(struct platform_device *pdev)reset_control_assert (pc->rst); -pm_runtime_force_suspend (&pdev->dev); +if (pm_runtime_force_suspend (&pdev->dev)) +pm_runtime_disable (&pdev->dev); }static int __maybe_unused tegra_pwm_runtime_suspend (struct device *dev)
This driver seems to be good candidate for devm_pm_runtime_enable. Using that, I think we can avoid any calls to pm_runtime_disable or pm_runtime_force_suspend.
Thanks
Mikko
Thanks, Mikko. I'll use devm_pm_runtime_enable() in v2 and retain cleanup for devices that remain active.
Best regards,
Myeonghun