]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bugfix i.mx6 pwm: prevent overflow of period_c * duty_ns
authorBrecht Neyrinck <bnrn@psicontrol.com>
Wed, 6 May 2015 07:57:48 +0000 (09:57 +0200)
committerStefano Babic <sbabic@denx.de>
Fri, 15 May 2015 17:20:47 +0000 (19:20 +0200)
Prevent overflow by casting duty_ns to ull first. This bug came up when trying to create a 200 Hz PWM

Signed-off-by: Brecht Neyrinck <bnrn@psicontrol.com>
Acked-by: Heiko Schocher<hs@denx.de>
drivers/pwm/pwm-imx-util.c

index f1d0b35d277eb2616ada02de08e0da774ed9fec2..79d86028de275962c78b3e728d7c420ac69b4a2b 100644 (file)
@@ -56,7 +56,7 @@ int pwm_imx_get_parms(int period_ns, int duty_ns, unsigned long *period_c,
        *prescale = *period_c / 0x10000 + 1;
 
        *period_c /= *prescale;
-       c = (unsigned long long)(*period_c * duty_ns);
+       c = *period_c * (unsigned long long)duty_ns;
        do_div(c, period_ns);
        *duty_c = c;