Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Thierry 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: Jingoo Han <jg1.han@samsung.com>

+3 -12
+1 -1
drivers/pwm/core.c
··· 371 371 */ 372 372 int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) 373 373 { 374 - if (!pwm || period_ns == 0 || duty_ns > period_ns) 374 + if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns) 375 375 return -EINVAL; 376 376 377 377 return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
-3
drivers/pwm/pwm-bfin.c
··· 69 69 unsigned long period, duty; 70 70 unsigned long long val; 71 71 72 - if (duty_ns < 0 || duty_ns > period_ns) 73 - return -EINVAL; 74 - 75 72 val = (unsigned long long)get_sclk() * period_ns; 76 73 do_div(val, NSEC_PER_SEC); 77 74 period = val;
-3
drivers/pwm/pwm-pxa.c
··· 70 70 unsigned long offset; 71 71 int rc; 72 72 73 - if (period_ns == 0 || duty_ns > period_ns) 74 - return -EINVAL; 75 - 76 73 offset = pwm->hwpwm ? 0x10 : 0; 77 74 78 75 c = clk_get_rate(pc->clk);
-3
drivers/pwm/pwm-samsung.c
··· 126 126 if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ) 127 127 return -ERANGE; 128 128 129 - if (duty_ns > period_ns) 130 - return -EINVAL; 131 - 132 129 if (period_ns == s3c->period_ns && 133 130 duty_ns == s3c->duty_ns) 134 131 return 0;
+1 -1
drivers/pwm/pwm-tiecap.c
··· 60 60 unsigned long period_cycles, duty_cycles; 61 61 unsigned int reg_val; 62 62 63 - if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC) 63 + if (period_ns > NSEC_PER_SEC) 64 64 return -ERANGE; 65 65 66 66 c = pc->clk_rate;
+1 -1
drivers/pwm/pwm-tiehrpwm.c
··· 221 221 unsigned short ps_divval, tb_divval; 222 222 int i, cmp_reg; 223 223 224 - if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC) 224 + if (period_ns > NSEC_PER_SEC) 225 225 return -ERANGE; 226 226 227 227 c = pc->clk_rate;