mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
pwm: Improve args checking in pwm_apply_state()
It seems like in the process of refactoring pwm_config() to utilize the
newly-introduced pwm_apply_state() API, some args/bounds checking was
dropped.
In particular, I noted that we are now allowing invalid period
selections, e.g.:
# echo 1 > /sys/class/pwm/pwmchip0/export
# cat /sys/class/pwm/pwmchip0/pwm1/period
100
# echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
[... driver may or may not reject the value, or trigger some logic bug ...]
It's better to see:
# echo 1 > /sys/class/pwm/pwmchip0/export
# cat /sys/class/pwm/pwmchip0/pwm1/period
100
# echo 101 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
-bash: echo: write error: Invalid argument
This patch reintroduces some bounds checks in both pwm_config() (for its
signed parameters; we don't want to convert negative values into large
unsigned values) and in pwm_apply_state() (which fix the above described
behavior, as well as other potential API misuses).
Fixes: 5ec803edcb ("pwm: Add core infrastructure to allow atomic updates")
Signed-off-by: Brian Norris <[email protected]>
Acked-by: Boris Brezillon <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
This commit is contained in:
parent
1a695a905c
commit
ef2bf4997f
2 changed files with 5 additions and 1 deletions
|
|
@ -457,7 +457,8 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
|
|||
{
|
||||
int err;
|
||||
|
||||
if (!pwm)
|
||||
if (!pwm || !state || !state->period ||
|
||||
state->duty_cycle > state->period)
|
||||
return -EINVAL;
|
||||
|
||||
if (!memcmp(state, &pwm->state, sizeof(*state)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue