[U-Boot] [PATCH v2] cfi_flash: precision and underflow problem in tout calculation

Thomas Chou thomas at wytron.com.tw
Wed Mar 24 01:55:28 CET 2010


From: Renato Andreola <renato.andreola at imagos.it>

With old configuration it could happen tout=0 if CONFIG_SYS_HZ<1000.

Signed-off-by: Alessandro Rubini <rubini at gnudd.com>
Signed-off-by: Renato Andreola <renato.andreola at imagos.it>
---
 drivers/mtd/cfi_flash.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index fdba297..cd1a86e 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -537,7 +537,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;
+	if ((ulong)CONFIG_SYS_HZ > 100000)
+		tout *= (ulong)CONFIG_SYS_HZ / 1000;  /* for a big HZ, avoid overflow */
+	else
+		tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000);
 #endif
 
 	/* Wait for command completion */
-- 
1.6.6.1



More information about the U-Boot mailing list