From 21d84ab72266f118794233176bd356d8b1cfdf35 Mon Sep 17 00:00:00 2001 From: Renato Andreola <renato.andre...@imagos.it> Date: Fri, 21 Aug 2009 18:05:51 +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. Signed-off-by: Alessandro Rubini <rub...@gnudd.com> Renato Andreola <renato.andre...@imagos.it> --- drivers/mtd/cfi_flash.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 81ac5d3..0d8fc54 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -660,9 +660,11 @@ 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 ((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 */ start = get_timer (0); while (flash_is_busy (info, sector)) { -- 1.5.5 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot