pwm: Fix invalid state detection
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Fri, 4 Jul 2025 17:24:17 +0000 (19:24 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 7 Jul 2025 06:33:44 +0000 (08:33 +0200)
Commit 9dd42d019e63 ("pwm: Allow pwm state transitions from an invalid
state") intended to allow some state transitions that were not allowed
before. The idea is sane and back then I also got the code comment
right, but the check for enabled is bogus. This resulted in state
transitions for enabled states to be allowed to have invalid duty/period
settings and thus it can happen that low-level drivers get requests for
invalid states🙄.

Invert the check to allow state transitions for disabled states only.

Fixes: 9dd42d019e63 ("pwm: Allow pwm state transitions from an invalid state")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20250704172416.626433-2-u.kleine-koenig@baylibre.com
Cc: stable@vger.kernel.org
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/core.c

index 4d842c69219445ff1c97ebdb9f1f64031c183a84..edf776b8ad53b9820a7fd85b810b379bae92b5d2 100644 (file)
@@ -596,7 +596,7 @@ static bool pwm_state_valid(const struct pwm_state *state)
         * and supposed to be ignored. So also ignore any strange values and
         * consider the state ok.
         */
-       if (state->enabled)
+       if (!state->enabled)
                return true;
 
        if (!state->period)