* [PATCH] pwm: renesas-tpu: Fix runtime PM reference leak
@ 2026-08-14 13:41 Ruoyu Wang
2026-08-16 7:22 ` Uwe Kleine-König
0 siblings, 1 reply; 2+ messages in thread
From: Ruoyu Wang @ 2026-08-14 13:41 UTC (permalink / raw)
To: Uwe Kleine-König, Thierry Reding, Laurent Pinchart, Axel Lin
Cc: linux-pwm, linux-kernel, Ruoyu Wang
tpu_pwm_timer_start() used pm_runtime_get_sync() without checking its
return value before touching the TPU clock. A failed runtime resume was
therefore ignored, and the callback continued into register access.
Use pm_runtime_resume_and_get() and propagate a failed resume. Keep the
matching put when clock preparation fails after a successful resume.
tpu_pwm_disable() also needs to propagate a failed start so that the PWM
apply callback does not access registers while runtime PM is inactive.
This issue was found by a static analysis checker and confirmed by manual
source review.
Fixes: 99b82abb0a35 ("pwm: Add Renesas TPU PWM driver")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
drivers/pwm/pwm-renesas-tpu.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
index 2196080b41770..c0bbe275275c8 100644
--- a/drivers/pwm/pwm-renesas-tpu.c
+++ b/drivers/pwm/pwm-renesas-tpu.c
@@ -149,10 +149,14 @@ static int tpu_pwm_timer_start(struct tpu_pwm_device *tpd)
if (!tpd->timer_on) {
/* Wake up device and enable clock. */
- pm_runtime_get_sync(&tpd->tpu->pdev->dev);
+ ret = pm_runtime_resume_and_get(&tpd->tpu->pdev->dev);
+ if (ret < 0)
+ return ret;
+
ret = clk_prepare_enable(tpd->tpu->clk);
if (ret) {
dev_err(&tpd->tpu->pdev->dev, "cannot enable clock\n");
+ pm_runtime_put(&tpd->tpu->pdev->dev);
return ret;
}
tpd->timer_on = true;
@@ -382,15 +386,21 @@ static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
return 0;
}
-static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+static int tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct tpu_device *tpu = to_tpu_device(chip);
struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm];
+ int ret;
/* The timer must be running to modify the pin output configuration. */
- tpu_pwm_timer_start(tpd);
+ ret = tpu_pwm_timer_start(tpd);
+ if (ret < 0)
+ return ret;
+
tpu_pwm_set_pin(tpd, TPU_PIN_INACTIVE);
tpu_pwm_timer_stop(tpd);
+
+ return 0;
}
static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -401,7 +411,10 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (state->polarity != pwm->state.polarity) {
if (enabled) {
- tpu_pwm_disable(chip, pwm);
+ err = tpu_pwm_disable(chip, pwm);
+ if (err)
+ return err;
+
enabled = false;
}
@@ -412,7 +425,7 @@ static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (!state->enabled) {
if (enabled)
- tpu_pwm_disable(chip, pwm);
+ return tpu_pwm_disable(chip, pwm);
return 0;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pwm: renesas-tpu: Fix runtime PM reference leak
2026-08-14 13:41 [PATCH] pwm: renesas-tpu: Fix runtime PM reference leak Ruoyu Wang
@ 2026-08-16 7:22 ` Uwe Kleine-König
0 siblings, 0 replies; 2+ messages in thread
From: Uwe Kleine-König @ 2026-08-16 7:22 UTC (permalink / raw)
To: Ruoyu Wang
Cc: Thierry Reding, Laurent Pinchart, Axel Lin, linux-pwm,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]
Hello,
On Fri, Aug 14, 2026 at 09:41:43PM +0800, Ruoyu Wang wrote:
> tpu_pwm_timer_start() used pm_runtime_get_sync() without checking its
> return value before touching the TPU clock. A failed runtime resume was
> therefore ignored, and the callback continued into register access.
>
> Use pm_runtime_resume_and_get() and propagate a failed resume. Keep the
> matching put when clock preparation fails after a successful resume.
>
> tpu_pwm_disable() also needs to propagate a failed start so that the PWM
> apply callback does not access registers while runtime PM is inactive.
>
> This issue was found by a static analysis checker and confirmed by manual
> source review.
>
> Fixes: 99b82abb0a35 ("pwm: Add Renesas TPU PWM driver")
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
Looks good to me. While it's a fix, I think it's not very urgent, we
lived with that since 13 years and is very unlikely to trigger.
So I applied it to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-nexxt
as 7.4-rc1 material. This branch isn't written in stone, so I'll still
take acks for the patch, and I will rebase it to 7.3-rc1 once that is
available.
Thanks for your contribution,
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-16 7:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 13:41 [PATCH] pwm: renesas-tpu: Fix runtime PM reference leak Ruoyu Wang
2026-08-16 7:22 ` Uwe Kleine-König
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.