[PATCH v2 5/5] pwm: img: Unregister PWM chip before disabling runtime PM and clocks

From: Lee Jones

Date: Mon Nov 23 2026 - 02:54:14 EST


img_pwm_remove() disables runtime PM and gates the peripheral clocks via
img_pwm_runtime_suspend() before calling pwmchip_remove(). While the
PWM chip is still registered, a consumer can call img_pwm_apply(), where
pm_runtime_resume_and_get() fails with -EACCES or img_pwm_disable()
writes to unclocked registers after img_pwm_runtime_suspend() has gated
the clocks.

Call pwmchip_remove() before disabling runtime PM, clearing autosuspend,
and suspending the device. Because chip and its private data are
allocated with devm_pwmchip_alloc(), driver data remains valid for any
pending runtime PM callbacks invoked during pm_runtime_disable() and
img_pwm_runtime_suspend() until devres teardown runs after
img_pwm_remove() returns.

Fixes: 277bb6a29e00 ("pwm: Imagination Technologies PWM DAC driver")
Closes: https://sashiko.dev/#/bug/linux-b06bab8d-dbf2-4ba2-9f5d-c5e141076abd
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

v1 => v2:
- Clear autosuspend in img_pwm_remove() and document why driver data
remains valid for runtime PM callbacks after pwmchip_remove() (Uwe)

drivers/pwm/pwm-img.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
index 91e0b19f0c08..7bf086b127c2 100644
--- a/drivers/pwm/pwm-img.c
+++ b/drivers/pwm/pwm-img.c
@@ -338,11 +338,12 @@ static void img_pwm_remove(struct platform_device *pdev)
{
struct pwm_chip *chip = platform_get_drvdata(pdev);

- pm_runtime_disable(&pdev->dev);
- if (!pm_runtime_status_suspended(&pdev->dev))
- img_pwm_runtime_suspend(&pdev->dev);
-
pwmchip_remove(chip);
+
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_dont_use_autosuspend(&pdev->dev);
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ img_pwm_runtime_suspend(&pdev->dev);
}

#ifdef CONFIG_PM_SLEEP
--
2.56.1.750.gf70dc682cf-goog