Skip to content

Commit c73a310

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: Handle .get_state() failures
This suppresses diagnosis for PWM_DEBUG routines and makes sure that pwm->state isn't modified in pwm_device_request() if .get_state() fails. Acked-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 500f879 commit c73a310

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/pwm/core.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
115115
}
116116

117117
if (pwm->chip->ops->get_state) {
118-
err = pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state);
119-
trace_pwm_get(pwm, &pwm->state, err);
118+
struct pwm_state state;
119+
120+
err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
121+
trace_pwm_get(pwm, &state, err);
122+
123+
if (!err)
124+
pwm->state = state;
120125

121126
if (IS_ENABLED(CONFIG_PWM_DEBUG))
122127
pwm->last = pwm->state;
@@ -460,6 +465,9 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
460465

461466
err = chip->ops->get_state(chip, pwm, &s1);
462467
trace_pwm_get(pwm, &s1, err);
468+
if (err)
469+
/* If that failed there isn't much to debug */
470+
return;
463471

464472
/*
465473
* The lowlevel driver either ignored .polarity (which is a bug) or as
@@ -524,6 +532,8 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
524532

525533
err = chip->ops->get_state(chip, pwm, last);
526534
trace_pwm_get(pwm, last, err);
535+
if (err)
536+
return;
527537

528538
/* reapplication of the current state should give an exact match */
529539
if (s1.enabled != last->enabled ||

0 commit comments

Comments
 (0)