From: Renato Andreola Date: Wed, 24 Mar 2010 15:00:47 +0000 (+0800) Subject: cfi_flash: precision and underflow problem in tout calculation X-Git-Tag: v2010.03-rc3~3^2^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c40c94a3d20a8616264c2dfcda85279185d69aeb;p=u-boot cfi_flash: precision and underflow problem in tout calculation With old configuration it could happen tout=0 if CONFIG_SYS_HZ<1000. Signed-off-by: Renato Andreola Signed-off-by: Alessandro Rubini Signed-off-by: Thomas Chou Signed-off-by: Stefan Roese --- diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index fdba297c88..cd1a86ebad 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 */