[PATCH 6/8] pwm: omap-dmtimer: Handle negative error codes from get_pwm_status()
From: Lee Jones
Date: Thu Nov 05 2026 - 09:42:07 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 check for negative error
codes before testing register bits.
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>
---
drivers/pwm/pwm-omap-dmtimer.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c
index 51830a87275c..1e4d8b9e224f 100644
--- a/drivers/pwm/pwm-omap-dmtimer.c
+++ b/drivers/pwm/pwm-omap-dmtimer.c
@@ -111,9 +111,11 @@ static void pwm_omap_dmtimer_start(struct pwm_omap_dmtimer_chip *omap)
*/
static bool 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 false;
return !!(status & OMAP_TIMER_CTRL_ST);
}
@@ -126,9 +128,11 @@ static bool pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap)
*/
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 PWM_POLARITY_NORMAL;
return !!(status & OMAP_TIMER_CTRL_SCPWM);
}
Cc: Lokesh Vutla <lokeshvutla@xxxxxx>
--
2.56.0.398.g882cbad275-goog