[U-Boot] [PATCH] bugfix i.mx6 pwm: prevent overflow of period_c * duty_ns

Stefano Babic sbabic at denx.de
Fri May 15 10:06:59 CEST 2015


On 06/05/2015 09:57, Brecht Neyrinck wrote:
> 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 at psicontrol.com>
> ---
>  drivers/pwm/pwm-imx-util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-imx-util.c b/drivers/pwm/pwm-imx-util.c
> index f1d0b35..79d86028 100644
> --- a/drivers/pwm/pwm-imx-util.c
> +++ b/drivers/pwm/pwm-imx-util.c
> @@ -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;
>  

Applied to u-boot-imx, thanks !

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list