From c40c94a3d20a8616264c2dfcda85279185d69aeb Mon Sep 17 00:00:00 2001 From: Renato Andreola Date: Wed, 24 Mar 2010 23:00:47 +0800 Subject: [PATCH] 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 --- drivers/mtd/cfi_flash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 */ -- 2.25.1