From mboxrd@z Thu Jan 1 00:00:00 1970 From: Renato Andreola Date: Thu, 06 Aug 2009 18:08:27 +0200 Subject: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix Message-ID: <4A7AFFFB.60105@imagos.it> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From 341dbd88695d3514699aae612d640ed93feb8821 Mon Sep 17 00:00:00 2001 From: Renato Andreola Date: Thu, 6 Aug 2009 18:05:00 +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 avoiding the preprocessor conditional and introducing a compile time branch between a high freq case and a slow freq case. Signed-off-by: Alessandro Rubini Renato Andreola --- drivers/mtd/cfi_flash.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 81ac5d3..499044f 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -659,9 +659,10 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector, { ulong start; -#if CONFIG_SYS_HZ != 1000 - tout *= CONFIG_SYS_HZ/1000; -#endif + if (CONFIG_SYS_HZ > 10000) + tout *= CONFIG_SYS_HZ/1000; /* for a big HZ, avoid overflow */ + else + tout = (tout * CONFIG_SYS_HZ) / 1000 + 1; /* Wait for command completion */ start = get_timer (0); -- 1.5.5