Skip to contentSkip to conversation

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

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

lore
Share & tools
lore

Yao Cheng

author
#0 lore raw

PATCH v2 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]>

---
Changes for v2:
- Coding style cleanup
- Move code after declarations to avoid warning

 arch/mips/cpu/mips32/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/cpu/mips32/cpu.c +5 -0
index 3ae397c..8fa53ba 100644
@@ -56,6 +56,11 @@ void flush_cache(ulong start_addr, ulong size)
 	unsigned long addr = start_addr & ~(lsize - 1);
 	unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
 
+	/* aend will be miscalculated when size is zero, so we return here */
+	if (size == 0) {
+		return;
+	}
+
 	while (1) {
 		cache_op(Hit_Writeback_Inv_D, addr);
 		cache_op(Hit_Invalidate_I, addr);
Signature · 1 line
1.7.4.1
#1 lore raw

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

in the future, please prefix your patches. since this is mips-specific, your summary would read:
mips: fix wrong loop bound in flush_cache() when "size" is zero

or perhaps:
mips32: fix wrong loop bound in flush_cache() when "size" is zero -mike

#2 lore raw

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

In reply to Yao Cheng

Hello.

Quoted 19 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]>

---
Changes for v2:
- Coding style cleanup
- Move code after declarations to avoid warning

  arch/mips/cpu/mips32/cpu.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/cpu/mips32/cpu.c +0 -0
index 3ae397c..8fa53ba 100644

arch/mips/cpu/mips32/cpu.c void flush_cache(ulong start_addr, ulong size) · line 62

Quoted 7 lines
arch/mips/cpu/mips32/cpu.c +4 -0
@@ -56,6 +56,11 @@ void flush_cache(ulong start_addr, ulong size)
  	unsigned long addr = start_addr&  ~(lsize - 1);
  	unsigned long aend = (start_addr + size - 1)&  ~(lsize - 1);
 
+	/* aend will be miscalculated when size is zero, so we return here */
+	if (size == 0) {
+		return;
+	}

{} not needed here.

WBR, Sergei