[U-Boot] [PATCH] Fix wrong loop bound in flush_cache() when "size" is zero.

Yao Cheng saturdaycoder at gmail.com
Mon Aug 8 10:07:48 CEST 2011


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.

Signed-off-by: Yao Cheng <saturdaycoder at gmail.com>
Cc: Shinya Kuribayashi <skuribay at pobox.com >
---
 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
index 3ae397c..1bf0094 100644
--- a/arch/mips/cpu/mips32/cpu.c
+++ b/arch/mips/cpu/mips32/cpu.c
@@ -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);
-- 
1.7.4.1



More information about the U-Boot mailing list