Skip to contentSkip to conversation

cfi_flash: precision and underflow problem in tout calculation

PATCH Superseded Thomas Chou 2 participants 5 messages Mar 24, 2010 – Mar 25, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cfi_flash: precision and underflow problem in tout calculation

From: Renato Andreola <[email protected]>

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

---
 drivers/mtd/cfi_flash.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/mtd/cfi_flash.c +4 -1
index fdba297..cd1a86e 100644
@@ -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 */
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH v2 1/1 cfi_flash: precision and underflow problem in tout calculation

Hi Thomas,

Quoted 6 lines · On Wednesday 24 March 2010 01:55:28 Thomas Chou wrote:

From: Renato Andreola <[email protected]>

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

Sorry for nitpicking again, but you need to add your S-o-b line as well? The order should be

since Renato is the original author.

Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

#2 lore raw

PATCH v2 1/1 cfi_flash: precision and underflow problem in tout calculation

Quoted 11 lines · Stefan Roese

Hi Thomas,

Quoted 7 lines · On Wednesday 24 March 2010 01:55:28 Thomas Chou wrote:

From: Renato Andreola<[email protected]>

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

Quoted 9 lines

Sorry for nitpicking again, but you need to add your S-o-b line as well? The order should be

since Renato is the original author.

Hi Stefan,

No problem. Please review again.

Best regards,
Thomas

#3 lore raw

PATCH v3 1/1 cfi_flash: precision and underflow problem in tout calculation

In reply to Thomas Chou

From: Renato Andreola <[email protected]>

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

---
 drivers/mtd/cfi_flash.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/mtd/cfi_flash.c +4 -1
index fdba297..cd1a86e 100644
@@ -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 */
Signature · 1 line
1.6.6.1
#4 lore raw

PATCH v3 1/1 cfi_flash: precision and underflow problem in tout calculation

Quoted 3 lines · On Wednesday 24 March 2010 16:00:47 Thomas Chou wrote:

From: Renato Andreola <[email protected]>

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

Applied to u-boot-cfi-flash/master. Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: [email protected]