pwm: sanity check values before passing them to the drivers
Check for valid period size before calling ops->config. This fixes the pxa driver which otherwise does a division by zero. While at it, also check for duty_ns being smaller or equal to period_ns. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Cc: Robert Jarzmik <robert.jarzmik@free.fr>
This commit is contained in:
parent
ab8a576a09
commit
f043520c5a
|
@ -177,6 +177,13 @@ int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
|
|||
{
|
||||
pwm->chip->duty_ns = duty_ns;
|
||||
pwm->chip->period_ns = period_ns;
|
||||
|
||||
if (period_ns == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (duty_ns > period_ns)
|
||||
return -EINVAL;
|
||||
|
||||
return pwm->chip->ops->config(pwm->chip, duty_ns, period_ns);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pwm_config);
|
||||
|
|
Loading…
Reference in New Issue