diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2019-01-07 20:49:37 +0100 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2019-01-10 09:32:23 +0100 |
commit | 309b32fb97d8cf0771373fb55e16b2852840c9aa (patch) | |
tree | 6ce2654c548f831cfd9938c9f632abe8a965823f /drivers | |
parent | bfeffd155283772bbe78c6a05dec7c0128ee500c (diff) | |
download | linux-309b32fb97d8cf0771373fb55e16b2852840c9aa.tar.bz2 |
pwm: Don't use memcmp() to compare state variables
Given that struct pwm_state is sparse (at least on some platforms),
variables of this type might represent the same state because all fields
are pairwise identical but still memcmp() returns a difference because
some of the unused bits are different.
To prevent surprises compare member by member instead of the whole
occupied memory.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/pwm/core.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1581f6ab1b1f..253a459fe0d8 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -472,7 +472,10 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) state->duty_cycle > state->period) return -EINVAL; - if (!memcmp(state, &pwm->state, sizeof(*state))) + if (state->period == pwm->state.period && + state->duty_cycle == pwm->state.duty_cycle && + state->polarity == pwm->state.polarity && + state->enabled == pwm->state.enabled) return 0; if (pwm->chip->ops->apply) { |