From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: Pengpeng Hou <pengpeng@iscas.ac.cn>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] pwm: fsl-ftm: Unwind resume failures
Date: Fri, 28 Aug 2026 17:20:14 +0800 [thread overview]
Message-ID: <20260828092014.9211-1-pengpeng@iscas.ac.cn> (raw)
fsl_pwm_resume() ignores all clock-enable and register-cache replay
failures. A failure can leave a prefix of requested PWM channels
holding clocks while runtime PM reports the chip resumed.
Check each acquisition and regcache_sync(), then unwind completed
channels in the reverse of the suspend order. Restore cache-only and
dirty state when the register replay fails.
The issue was identified via static analysis and manually reviewed.
Fixes: 97d0b42e39a7 ("pwm: ftm: Add Power Management support for FTM PWM")
Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/pwm/pwm-fsl-ftm.c | 44 +++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c
index 35406b2e1925..7a61ccb75963 100644
--- a/drivers/pwm/pwm-fsl-ftm.c
+++ b/drivers/pwm/pwm-fsl-ftm.c
@@ -501,7 +501,7 @@ static int fsl_pwm_resume(struct device *dev)
{
struct pwm_chip *chip = dev_get_drvdata(dev);
struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
- int i;
+ int i, ret;
for (i = 0; i < chip->npwm; i++) {
struct pwm_device *pwm = &chip->pwms[i];
@@ -509,20 +509,52 @@ static int fsl_pwm_resume(struct device *dev)
if (!test_bit(PWMF_REQUESTED, &pwm->flags))
continue;
- clk_prepare_enable(fpc->ipg_clk);
+ ret = clk_prepare_enable(fpc->ipg_clk);
+ if (ret)
+ goto unwind;
if (!pwm_is_enabled(pwm))
continue;
- clk_prepare_enable(fpc->clk[fpc->period.clk_select]);
- clk_prepare_enable(fpc->clk[FSL_PWM_CLK_CNTEN]);
+ ret = clk_prepare_enable(fpc->clk[fpc->period.clk_select]);
+ if (ret) {
+ clk_disable_unprepare(fpc->ipg_clk);
+ goto unwind;
+ }
+
+ ret = clk_prepare_enable(fpc->clk[FSL_PWM_CLK_CNTEN]);
+ if (ret) {
+ clk_disable_unprepare(fpc->clk[fpc->period.clk_select]);
+ clk_disable_unprepare(fpc->ipg_clk);
+ goto unwind;
+ }
}
/* restore all registers from cache */
regcache_cache_only(fpc->regmap, false);
- regcache_sync(fpc->regmap);
+ ret = regcache_sync(fpc->regmap);
+ if (!ret)
+ return 0;
- return 0;
+ regcache_cache_only(fpc->regmap, true);
+ regcache_mark_dirty(fpc->regmap);
+
+unwind:
+ while (i--) {
+ struct pwm_device *pwm = &chip->pwms[i];
+
+ if (!test_bit(PWMF_REQUESTED, &pwm->flags))
+ continue;
+
+ if (pwm_is_enabled(pwm)) {
+ clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_CNTEN]);
+ clk_disable_unprepare(fpc->clk[fpc->period.clk_select]);
+ }
+
+ clk_disable_unprepare(fpc->ipg_clk);
+ }
+
+ return ret;
}
#endif
--
2.43.0
next reply other threads:[~2026-08-28 9:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 9:20 Pengpeng Hou [this message]
2026-09-11 7:32 ` Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260828092014.9211-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®