public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
@ 2009-08-06 13:09 Renato Andreola
  2009-08-06 13:22 ` Wolfgang Denk
  2009-08-06 20:26 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 33+ messages in thread
From: Renato Andreola @ 2009-08-06 13:09 UTC (permalink / raw)
  To: u-boot

 From 3723c8437d8c3d2e04bc3bc1de9c21b33072ab08 Mon Sep 17 00:00:00 2001
From: Renato Andreola <renato.andreola@imagos.it>
Date: Thu, 6 Aug 2009 14:49:59 +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
solved avoiding the preprocessor conditional and introducing a compile 
time branch between a high freq case and a slow freq case.

Signed-off-by: Renato Andreola renato.andreola@imagos.it
---
  drivers/mtd/cfi_flash.c |    7 ++++---
  1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..b118f71 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,9 +659,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;
-#endif
+        if (CONFIG_SYS_HZ > 10000)
+                tout *= CONFIG_SYS_HZ/1000;  /* for a big HZ, avoid 
overflow */
+        else
+                tout = tout * CONFIG_SYS_HZ / 1000 + 1;

  	/* Wait for command completion */
  	start = get_timer (0);
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 33+ messages in thread
* [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
@ 2009-08-24  8:32 Renato Andreola
  2009-08-25 13:25 ` Shinya Kuribayashi
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Renato Andreola @ 2009-08-24  8:32 UTC (permalink / raw)
  To: u-boot

 From 21d84ab72266f118794233176bd356d8b1cfdf35 Mon Sep 17 00:00:00 2001
From: Renato Andreola <renato.andreola@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 <rubini@gnudd.com> Renato Andreola <renato.andreola@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

^ permalink raw reply related	[flat|nested] 33+ messages in thread
* [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
@ 2009-08-06 16:08 Renato Andreola
  0 siblings, 0 replies; 33+ messages in thread
From: Renato Andreola @ 2009-08-06 16:08 UTC (permalink / raw)
  To: u-boot

 From 341dbd88695d3514699aae612d640ed93feb8821 Mon Sep 17 00:00:00 2001
From: Renato Andreola <renato.andreola@imagos.it>
Date: Thu, 6 Aug 2009 18:05:00 +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
solved avoiding the preprocessor conditional and introducing a compile time branch between a high freq case and a slow freq case.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com> Renato Andreola <renato.andreola@imagos.it>
---
  drivers/mtd/cfi_flash.c |    7 ++++---
  1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..499044f 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,9 +659,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;
-#endif
+        if (CONFIG_SYS_HZ > 10000)
+		tout *= CONFIG_SYS_HZ/1000;  /* for a big HZ, avoid overflow */
+        else
+		tout = (tout * CONFIG_SYS_HZ) / 1000 + 1;

  	/* Wait for command completion */
  	start = get_timer (0);
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 33+ messages in thread
* [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
@ 2009-08-06  9:49 Renato Andreola
  2009-08-06 10:07 ` Wolfgang Denk
  2009-08-06 10:12 ` Alessandro Rubini
  0 siblings, 2 replies; 33+ messages in thread
From: Renato Andreola @ 2009-08-06  9:49 UTC (permalink / raw)
  To: u-boot

 From be54cb97ca26bcbbc1a908d1f2a5447b6639dc59 Mon Sep 17 00:00:00 2001
From: Renato Andreola <renato.andreola@imagos.it>
Date: Thu, 6 Aug 2009 11:40:52 +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
solved using an unsigned long long

Signed-off-by: Renato Andreola renato.andreola@imagos.it
---
  drivers/mtd/cfi_flash.c |    6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..6bcd102 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,8 +659,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 CONFIG_SYS_HZ != 1000	
+	unsigned long long ull;
+	ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
+	tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */
  #endif

  	/* Wait for command completion */
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 33+ messages in thread
* [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
@ 2009-04-10 12:28 Renato Andreola
  2009-04-13 22:09 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 33+ messages in thread
From: Renato Andreola @ 2009-04-10 12:28 UTC (permalink / raw)
  To: u-boot

 From 6cc63851e5e4c16012d9afad70cedb41b7340de7 Mon Sep 17 00:00:00 2001
From: Renato Andreola <renato.andreola@imagos.it>
Date: Fri, 10 Apr 2009 12:52:55 +0200
Subject: drivers/mtd/cfi_flash: precision and underflow problem in tout 
calculation

With old configuration it could happen tout=0 if CONFIG_SYS_HZ<1000
solved using an unsigned long long
---
  drivers/mtd/cfi_flash.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 175d82a..0aa42a2 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -660,7 +660,9 @@ 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;
+	unsigned long long ull;
+	ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
+	tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */
  #endif

  	/* Wait for command completion */
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2009-11-23 19:36 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-06 13:09 [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix Renato Andreola
2009-08-06 13:22 ` Wolfgang Denk
2009-08-06 13:31   ` Alessandro Rubini
2009-08-06 14:19     ` Wolfgang Denk
2009-08-06 20:26 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-06 20:53   ` Wolfgang Denk
2009-08-06 21:01     ` Wolfgang Denk
2009-08-06 21:15     ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-06 21:35       ` Wolfgang Denk
2009-08-07  8:15     ` Renato Andreola
2009-08-07  9:16       ` Wolfgang Denk
2009-08-07 10:29         ` [U-Boot] Kirkwood gpio (was: timeout calculation underflow if imprecise 1kHz timer: fix) Alessandro Rubini
2009-08-07 11:13           ` Prafulla Wadaskar
2009-08-07 12:10             ` [U-Boot] Kirkwood gpio Heiko Schocher
2009-08-07 11:46           ` Heiko Schocher
2009-08-07 11:48           ` [U-Boot] Kirkwood gpio (was: timeout calculation underflow if imprecise 1kHz timer: fix) Dieter Kiermaier
2009-08-07 12:14         ` [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix Renato Andreola
2009-08-09 21:13           ` Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2009-08-24  8:32 Renato Andreola
2009-08-25 13:25 ` Shinya Kuribayashi
2009-08-25 15:01   ` Renato Andreola
2009-08-25 15:39 ` Stefan Roese
2009-08-25 15:44   ` Stefan Roese
2009-11-22 21:09 ` Wolfgang Denk
2009-11-23  8:51   ` Renato Andreola
2009-11-23 19:36     ` Wolfgang Denk
2009-08-06 16:08 Renato Andreola
2009-08-06  9:49 Renato Andreola
2009-08-06 10:07 ` Wolfgang Denk
2009-08-06 10:12 ` Alessandro Rubini
     [not found]   ` <4A7AB614.2020509@imagos.it>
2009-08-06 11:40     ` Wolfgang Denk
2009-04-10 12:28 Renato Andreola
2009-04-13 22:09 ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox