[PATCH]: x86_64: Remove unnecessary cast in prefetch()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andi Kleen <ak@...>
Cc: <patches@...>, <linux-kernel@...>
Date: Thursday, September 6, 2007 - 5:27 pm

It is ok to call prefetch() function with NULL argument, as specifically
commented in include/linux/prefetch.h.  But in standard C, it is invalid to
dereference NULL pointer (see C99 standard 6.5.3.2 paragraph 4 and note #84).
Newer gcc versions (4.3 and above) will use that to conclude that "x"
argument is non-null and thus wreaking havok everywhere prefetch() was inlined.
Fixed by removing cast and changing asm constraint.

This can be fixed better by using gcc's __builtin_prefetch().

Signed-off-by: Serge Belyshev <belyshev@depni.sinp.msu.ru>

---
 include/asm-x86_64/processor.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/include/asm-x86_64/processor.h
===================================================================
--- linux.orig/include/asm-x86_64/processor.h
+++ linux/include/asm-x86_64/processor.h
@@ -373,7 +373,7 @@ static inline void sync_core(void)
 #define ARCH_HAS_PREFETCH
 static inline void prefetch(void *x) 
 { 
-	asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
+	asm volatile("prefetcht0 (%0)" :: "r" (x));
 } 
 
 #define ARCH_HAS_PREFETCHW 1
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH]: x86_64: Remove unnecessary cast in prefetch(), Serge Belyshev, (Thu Sep 6, 5:27 pm)
Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch(), Serge Belyshev, (Sat Sep 15, 2:40 am)
Re: [PATCH]: x86_64: Remove unnecessary cast in prefetch(), Serge Belyshev, (Sat Sep 15, 5:16 pm)