[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

Wolfgang Denk wd at denx.de
Thu Aug 6 12:07:28 CEST 2009


Dear Renato Andreola,

In message <4A7AA72C.8010704 at imagos.it> you wrote:
>  From be54cb97ca26bcbbc1a908d1f2a5447b6639dc59 Mon Sep 17 00:00:00 2001
> From: Renato Andreola <renato.andreola at imagos.it>
> Date: Thu, 6 Aug 2009 11:40:52 +0200
> Subject: [PATCH] drivers/mtd/cfi_flash: precision and underflow problem 
> in tout calculation
> 
> With old configuration it could happen tout=0 if CONFIG_SYS_HZ<1000
> solved using an unsigned long long

I don't like this implementation - using LL divisions just pulls in
more dependencies on libgcc code and the like, and blows up the code
size.

> -#if CONFIG_SYS_HZ != 1000
> -	tout *= CONFIG_SYS_HZ/1000;
> +#if CONFIG_SYS_HZ != 1000	
> +	unsigned long long ull;
> +	ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
> +	tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */

I think rounding up should be sufficient here, i. e. something like:

	tout *= DIV_ROUND_UP(CONFIG_SYS_HZ,1000);

?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Ninety-Ninety Rule of Project Schedules:
        The first ninety percent of the task takes ninety percent of
the time, and the last ten percent takes the other ninety percent.


More information about the U-Boot mailing list