Commit c2d476a9 authored by Thierry Reding's avatar Thierry Reding

pwm: Check for negative duty-cycle and period

Make sure the duty-cycle and period passed in are not negative. This
should eventually be made implicit by making them unsigned. While at
it, the drivers' .config() implementations can have the equivalent
checks removed.
Signed-off-by: default avatarThierry Reding <thierry.reding@avionic-design.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Axel Lin <axel.lin@gmail.com>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Jonghwan Choi <jhbird.choi@samsung.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: "Philip, Avinash" <avinashphilip@ti.com>
Cc: Vaibhav Bedia <vaibhav.bedia@ti.com>
Acked-by: default avatarJingoo Han <jg1.han@samsung.com>
parent f6b8a570
...@@ -371,7 +371,7 @@ EXPORT_SYMBOL_GPL(pwm_free); ...@@ -371,7 +371,7 @@ EXPORT_SYMBOL_GPL(pwm_free);
*/ */
int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
{ {
if (!pwm || period_ns == 0 || duty_ns > period_ns) if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns)
return -EINVAL; return -EINVAL;
return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns); return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
......
...@@ -69,9 +69,6 @@ static int bfin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -69,9 +69,6 @@ static int bfin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned long period, duty; unsigned long period, duty;
unsigned long long val; unsigned long long val;
if (duty_ns < 0 || duty_ns > period_ns)
return -EINVAL;
val = (unsigned long long)get_sclk() * period_ns; val = (unsigned long long)get_sclk() * period_ns;
do_div(val, NSEC_PER_SEC); do_div(val, NSEC_PER_SEC);
period = val; period = val;
......
...@@ -70,9 +70,6 @@ static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -70,9 +70,6 @@ static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned long offset; unsigned long offset;
int rc; int rc;
if (period_ns == 0 || duty_ns > period_ns)
return -EINVAL;
offset = pwm->hwpwm ? 0x10 : 0; offset = pwm->hwpwm ? 0x10 : 0;
c = clk_get_rate(pc->clk); c = clk_get_rate(pc->clk);
......
...@@ -126,9 +126,6 @@ static int s3c_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -126,9 +126,6 @@ static int s3c_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ) if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ)
return -ERANGE; return -ERANGE;
if (duty_ns > period_ns)
return -EINVAL;
if (period_ns == s3c->period_ns && if (period_ns == s3c->period_ns &&
duty_ns == s3c->duty_ns) duty_ns == s3c->duty_ns)
return 0; return 0;
......
...@@ -60,7 +60,7 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -60,7 +60,7 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned long period_cycles, duty_cycles; unsigned long period_cycles, duty_cycles;
unsigned int reg_val; unsigned int reg_val;
if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC) if (period_ns > NSEC_PER_SEC)
return -ERANGE; return -ERANGE;
c = pc->clk_rate; c = pc->clk_rate;
......
...@@ -221,7 +221,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -221,7 +221,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
unsigned short ps_divval, tb_divval; unsigned short ps_divval, tb_divval;
int i, cmp_reg; int i, cmp_reg;
if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC) if (period_ns > NSEC_PER_SEC)
return -ERANGE; return -ERANGE;
c = pc->clk_rate; c = pc->clk_rate;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment