Commit c40c94a3d20a8616264c2dfcda85279185d69aeb

Authored by Renato Andreola
Committed by Stefan Roese
1 parent 7027d5622d

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 <renato.andreola@imagos.it>
Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Signed-off-by: Stefan Roese <sr@denx.de>

Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff

drivers/mtd/cfi_flash.c
... ... @@ -537,7 +537,10 @@
537 537 ulong start;
538 538  
539 539 #if CONFIG_SYS_HZ != 1000
540   - tout *= CONFIG_SYS_HZ/1000;
  540 + if ((ulong)CONFIG_SYS_HZ > 100000)
  541 + tout *= (ulong)CONFIG_SYS_HZ / 1000; /* for a big HZ, avoid overflow */
  542 + else
  543 + tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000);
541 544 #endif
542 545  
543 546 /* Wait for command completion */