Skip to contentSkip to conversation

ppc: Fix roll over bug in flush_cache()

PATCH New Kumar Gala 2 participants 2 messages Feb 6, 2009 – Feb 9, 2009

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 ppc: Fix roll over bug in flush_cache()

If we call flush_cache(0xfffff000, 0x1000) it would never terminate the loop since end = 0xffffffff and we'd roll over our counter from 0xfffffe0 to 0 (assuming a 32-byte cache line)

---
 lib_ppc/cache.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
lib_ppc/cache.c +4 -2
index 1292b71..338b08b 100644
@@ -33,14 +33,16 @@ void flush_cache(ulong start_addr, ulong size)
 	start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
 	end = start_addr + size - 1;
 
-	for (addr = start; addr <= end; addr += CONFIG_SYS_CACHELINE_SIZE) {
+	for (addr = start; (addr <= end) && (addr >= start);
+			addr += CONFIG_SYS_CACHELINE_SIZE) {
 		asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
 		WATCHDOG_RESET();
 	}
 	/* wait for all dcbst to complete on bus */
 	asm volatile("sync" : : : "memory");
 
-	for (addr = start; addr <= end; addr += CONFIG_SYS_CACHELINE_SIZE) {
+	for (addr = start; (addr <= end) && (addr >= start);
+			addr += CONFIG_SYS_CACHELINE_SIZE) {
 		asm volatile("icbi 0,%0" : : "r" (addr) : "memory");
 		WATCHDOG_RESET();
 	}
Signature · 1 line
1.5.6.6
#1 lore raw

PATCH 1/1 ppc: Fix roll over bug in flush_cache()

Dear Kumar Gala,

Quoted 8 lines · In message <[email protected]> you…

If we call flush_cache(0xfffff000, 0x1000) it would never terminate the loop since end = 0xffffffff and we'd roll over our counter from 0xfffffe0 to 0 (assuming a 32-byte cache line)

---
 lib_ppc/cache.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Probably the best operating system in the world  is  the  [operating
system] made for the PDP-11 by Bell Laboratories."
                                           - Ted Nelson, October 1977