From: Wolfgang Denk Date: Thu, 06 Aug 2009 12:07:28 +0200 Subject: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix In-Reply-To: <4A7AA72C.8010704@imagos.it> References: <4A7AA72C.8010704@imagos.it> Message-ID: <20090806100728.3C3EC832E416@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Renato Andreola, In message <4A7AA72C.8010704@imagos.it> you wrote: > From be54cb97ca26bcbbc1a908d1f2a5447b6639dc59 Mon Sep 17 00:00:00 2001 > From: Renato Andreola > 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.