[PATCH v2 3/5] pwm: omap-dmtimer: Propagate get_pwm_status() errors in apply()
From: Lee Jones
Date: Mon Nov 23 2026 - 02:54:02 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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