[U-Boot] [PATCH] bugfix i.mx6 pwm: prevent overflow of period_c * duty_ns by casting duty_ns to ull first. This bug came up when trying to create a 200 Hz PWM.

Heiko Schocher hs at denx.de
Tue Apr 28 07:32:11 CEST 2015


Hello Brecht Neyrinck,

Am 27.04.2015 14:11, schrieb Brecht Neyrinck:
> ---
>   drivers/pwm/pwm-imx-util.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>   mode change 100644 => 100755 drivers/pwm/pwm-imx-util.c
>
> diff --git a/drivers/pwm/pwm-imx-util.c b/drivers/pwm/pwm-imx-util.c
> index f1d0b35..777a8bf 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;

Thanks for this ... Hmm... this code is directly from linux
drivers/pwm/pwm-imx.c ... Do you have running a linux on your hw?
Could you verify this in linux too?

Thanks!

Acked-by: Heiko Schocher <hs at denx.de>

bye,
Heiko
>   	do_div(c, period_ns);
>   	*duty_c = c;
>
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany


More information about the U-Boot mailing list