From: Wolfgang Denk Date: Fri, 07 Aug 2009 11:16:47 +0200 Subject: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix In-Reply-To: <4A7BE28A.8080701@imagos.it> References: <4A7AD624.9030902@imagos.it> <20090806202615.GH13346@game.jcrosoft.org> <20090806205329.8A31C832E416@gemini.denx.de> <4A7BE28A.8080701@imagos.it> Message-ID: <20090807091647.3F231832E416@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 <4A7BE28A.8080701@imagos.it> you wrote: > > I'd like to clarify what is the problem with the timeout and the Intel > flash (even if the following comments can be obvious or already well > known) and to ask you an opinion on a small code change. Thanks. ... > I think that an expression like this > > #if CONFIG_SYS_HZ != 1000 > if ((ulong)CONFIG_SYS_HZ > 10000) > tout *= ((ulong)CONFIG_SYS_HZ)/1000; /* for a big HZ, avoid > overflow */ > else > tout = (tout * (ulong)CONFIG_SYS_HZ + 500) / 1000; > #endif > > could be better because > - it forces the data type of the system dependent CONFIG_SYS_HZ value to > ulong (no float!) > - it rounds tout to 0.5 timer tick and leaves tout unchanged if > CONFIG_SYS_HZ == 1000 > > What do you think about? I'd prefer "tout = DIV_ROUND_UP(tout*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 I came home the other night and tried to open the door with my car keys...and the building started up. So I took it out for a drive. A cop pulled me over for speeding. He asked me where I live... "Right here". - Steven Wright