From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, "Uwe Kleine-König" <ukleinek@kernel.org>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Uwe Kleine-König (The Capable Hub)"
<u.kleine-koenig@baylibre.com>, "Chen Wang" <chen.wang@linux.dev>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Joachim Eastwood" <manabian@gmail.com>,
NeilBrown <neil@brown.name>,
"Grant Erickson" <marathon96@gmail.com>,
"Lokesh Vutla" <lokeshvutla@ti.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH v2 3/5] pwm: omap-dmtimer: Propagate get_pwm_status() errors in apply()
Date: Mon, 23 Nov 2026 07:52:53 +0000 [thread overview]
Message-ID: <20261123075320.379664-4-lee@kernel.org> (raw)
In-Reply-To: <20261123075320.379664-1-lee@kernel.org>
omap->pdata->get_pwm_status() returns a signed int that can be a
negative error code on runtime PM failure or invalid timer cookie.
pwm_omap_dmtimer_is_enabled() and pwm_omap_dmtimer_polarity() store the
return value in an unsigned u32 and test OMAP_TIMER_CTRL_ST (BIT(0)) and
OMAP_TIMER_CTRL_SCPWM (BIT(7)), misinterpreting negative error codes
(such as -EINVAL or -EACCES) as an enabled or inverted timer.
Store the return value in a signed int and propagate negative error
codes through to pwm_omap_dmtimer_apply().
Fixes: 6b28fb6f3ca3 ("pwm: omap-dmtimer: Implement .apply callback")
Closes: https://sashiko.dev/#/bug/linux-f4782faa-466d-43a8-85d8-6d6181ee2243
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
v1 => v2:
- Propagate negative get_pwm_status() error codes through to
pwm_omap_dmtimer_apply() (Uwe)
drivers/pwm/pwm-omap-dmtimer.c | 54 +++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 14 deletions(-)
diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c
index 51830a87275c..08d444b3928e 100644
--- a/drivers/pwm/pwm-omap-dmtimer.c
+++ b/drivers/pwm/pwm-omap-dmtimer.c
@@ -107,13 +107,15 @@ static void pwm_omap_dmtimer_start(struct pwm_omap_dmtimer_chip *omap)
* pwm_omap_dmtimer_is_enabled() - Detect if the pwm is enabled.
* @omap: Pointer to pwm omap dm timer chip
*
- * Return true if pwm is enabled else false.
+ * Return: 1 if pwm is enabled, 0 if disabled, or negative error code.
*/
-static bool pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap)
+static int pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap)
{
- u32 status;
+ int status;
status = omap->pdata->get_pwm_status(omap->dm_timer);
+ if (status < 0)
+ return status;
return !!(status & OMAP_TIMER_CTRL_ST);
}
@@ -122,13 +124,15 @@ static bool pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap)
* pwm_omap_dmtimer_polarity() - Detect the polarity of pwm.
* @omap: Pointer to pwm omap dm timer chip
*
- * Return the polarity of pwm.
+ * Return: Polarity of pwm, or negative error code.
*/
static int pwm_omap_dmtimer_polarity(struct pwm_omap_dmtimer_chip *omap)
{
- u32 status;
+ int status;
status = omap->pdata->get_pwm_status(omap->dm_timer);
+ if (status < 0)
+ return status;
return !!(status & OMAP_TIMER_CTRL_SCPWM);
}
@@ -237,16 +241,21 @@ static int pwm_omap_dmtimer_config(struct pwm_chip *chip,
* @chip: Pointer to PWM controller
* @pwm: Pointer to PWM channel
* @polarity: New pwm polarity to be set
+ *
+ * Return: 0 if successfully changed the polarity else appropriate error.
*/
-static void pwm_omap_dmtimer_set_polarity(struct pwm_chip *chip,
- struct pwm_device *pwm,
- enum pwm_polarity polarity)
+static int pwm_omap_dmtimer_set_polarity(struct pwm_chip *chip,
+ struct pwm_device *pwm,
+ enum pwm_polarity polarity)
{
struct pwm_omap_dmtimer_chip *omap = to_pwm_omap_dmtimer_chip(chip);
- bool enabled;
+ int enabled;
/* Disable the PWM before changing the polarity. */
enabled = pwm_omap_dmtimer_is_enabled(omap);
+ if (enabled < 0)
+ return enabled;
+
if (enabled)
omap->pdata->stop(omap->dm_timer);
@@ -257,6 +266,8 @@ static void pwm_omap_dmtimer_set_polarity(struct pwm_chip *chip,
if (enabled)
pwm_omap_dmtimer_start(omap);
+
+ return 0;
}
/**
@@ -272,22 +283,37 @@ static int pwm_omap_dmtimer_apply(struct pwm_chip *chip,
const struct pwm_state *state)
{
struct pwm_omap_dmtimer_chip *omap = to_pwm_omap_dmtimer_chip(chip);
- int ret;
+ int enabled, polarity, ret;
- if (pwm_omap_dmtimer_is_enabled(omap) && !state->enabled) {
+ enabled = pwm_omap_dmtimer_is_enabled(omap);
+ if (enabled < 0)
+ return enabled;
+
+ if (enabled && !state->enabled) {
omap->pdata->stop(omap->dm_timer);
return 0;
}
- if (pwm_omap_dmtimer_polarity(omap) != state->polarity)
- pwm_omap_dmtimer_set_polarity(chip, pwm, state->polarity);
+ polarity = pwm_omap_dmtimer_polarity(omap);
+ if (polarity < 0)
+ return polarity;
+
+ if (polarity != state->polarity) {
+ ret = pwm_omap_dmtimer_set_polarity(chip, pwm, state->polarity);
+ if (ret)
+ return ret;
+ }
ret = pwm_omap_dmtimer_config(chip, pwm, state->duty_cycle,
state->period);
if (ret)
return ret;
- if (!pwm_omap_dmtimer_is_enabled(omap) && state->enabled) {
+ enabled = pwm_omap_dmtimer_is_enabled(omap);
+ if (enabled < 0)
+ return enabled;
+
+ if (!enabled && state->enabled) {
omap->pdata->set_pwm(omap->dm_timer,
state->polarity == PWM_POLARITY_INVERSED,
true,
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 7:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 7:52 [PATCH v2 0/5] pwm: Fix various bugs reported by Sashiko Lee Jones
2026-11-23 7:52 ` [PATCH v2 1/5] pwm: mxs: Return early when disabling and fix error-path clock leak Lee Jones
2026-11-23 7:52 ` [PATCH v2 2/5] pwm: fsl-ftm: Enable ipg_clk around regcache_sync() during resume Lee Jones
2026-11-23 7:52 ` Lee Jones [this message]
2026-11-23 7:52 ` [PATCH v2 4/5] pwm: tiehrpwm: Enable runtime PM before registering PWM chip Lee Jones
2026-11-23 7:52 ` [PATCH v2 5/5] pwm: img: Unregister PWM chip before disabling runtime PM and clocks Lee Jones
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=20261123075320.379664-4-lee@kernel.org \
--to=lee@kernel.org \
--cc=chen.wang@linux.dev \
--cc=geert+renesas@glider.be \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=lokeshvutla@ti.com \
--cc=manabian@gmail.com \
--cc=marathon96@gmail.com \
--cc=neil.armstrong@linaro.org \
--cc=neil@brown.name \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@baylibre.com \
--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®