Skip to contentSkip to conversation

Fix wrong loop bound in flush_cache() when "size" is zero.

PATCH New Yao Cheng 3 participants 4 messages Aug 8, 2011 MIPS

lore
Share & tools
lore

Yao Cheng

author
#0 lore raw

PATCH 1/1 Fix wrong loop bound in flush_cache() when "size" is zero.

The issue is found when calling flush_cache() with zero "size" argument.
The bound of loop is miscalculated in this case and flush_cache() enters a wrong flushing loop. To fix this issue I skipped the operations when "size" is found to be zero.

Cc Shinya Kuribayashi <[email protected] >
---
 arch/mips/cpu/mips32/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/cpu/mips32/cpu.c +5 -0
index 3ae397c..1bf0094 100644
@@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 void flush_cache(ulong start_addr, ulong size)
 {
+  /* aend will be miscalculated when size is zero, so we need return here */
+  if (size == 0) {
+    return;
+  }
+
 	unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
 	unsigned long addr = start_addr & ~(lsize - 1);
 	unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 Fix wrong loop bound in flush_cache() when "size" is zero.

Hello.

Quoted 15 lines · Yao Cheng

The issue is found when calling flush_cache() with zero "size" argument.
The bound of loop is miscalculated in this case and flush_cache() enters a wrong flushing loop. To fix this issue I skipped the operations when "size" is found to be zero.

Cc Shinya Kuribayashi<[email protected]>
---
  arch/mips/cpu/mips32/cpu.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/cpu/mips32/cpu.c +0 -0
index 3ae397c..1bf0094 100644

arch/mips/cpu/mips32/cpu.c int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 59

Quoted 8 lines
arch/mips/cpu/mips32/cpu.c +5 -0
@@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
  void flush_cache(ulong start_addr, ulong size)
  {
+  /* aend will be miscalculated when size is zero, so we need return here */
+  if (size == 0) {
+    return;
+  }
+

Please indent with tabs, not spaces. Also, doesn't this code generate
warning (code before declarations)?

arch/mips/cpu/mips32/cpu.c int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 62

Quoted 3 lines
arch/mips/cpu/mips32/cpu.c +0 -0
  	unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  	unsigned long addr = start_addr&  ~(lsize - 1);
  	unsigned long aend = (start_addr + size - 1)&  ~(lsize - 1);

WBR, Sergei

#2 lore raw

PATCH 1/1 Fix wrong loop bound in flush_cache() when "size" is zero.

Hi Sergei, thanks for your comments.
I will submit the patch v2.

2011/8/8 Sergei Shtylyov <[email protected]>

Quoted 47 lines

Hello.

On 08-08-2011 12:07, Yao Cheng wrote:

The issue is found when calling flush_cache() with zero "size" argument.

Quoted 5 lines

The bound of loop is miscalculated in this case and flush_cache() enters a wrong flushing loop.
To fix this issue I skipped the operations when "size" is found to be zero.

Quoted 5 lines
Cc Shinya Kuribayashi<[email protected]**>
---
 arch/mips/cpu/mips32/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/mips/cpu/mips32/cpu.c b/arch/mips/cpu/mips32/cpu.c

Quoted 5 lines

index 3ae397c..1bf0094 100644

arch/mips/cpu/mips32/cpu.c +0 -0
@@ -52,6 +52,11 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char
 * const argv[])

arch/mips/cpu/mips32/cpu.c int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char · line 62

Quoted 10 lines
arch/mips/cpu/mips32/cpu.c +5 -0
 
 void flush_cache(ulong start_addr, ulong size)
 {
+  /* aend will be miscalculated when size is zero, so we need return here
 */
+  if (size == 0) {
+    return;
+  }
 
+

Please indent with tabs, not spaces. Also, doesn't this code generate
warning (code before declarations)?

        unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
Quoted 3 lines
       unsigned long addr = start_addr&  ~(lsize - 1);
       unsigned long aend = (start_addr + size - 1)&  ~(lsize - 1);

WBR, Sergei

#3 lore raw

PATCH 1/1 Fix wrong loop bound in flush_cache() when "size" is zero.

In reply to Sergei Shtylyov
Quoted 2 lines · Sergei Shtylyov

Please indent with tabs, not spaces. Also, doesn't this code generate
warning (code before declarations)?

Only with -Wdeclaration-after-statement, which U-boot doesn't set.

-Scott