Skip to content

Commit

Permalink
Remove unnecessary cast in prefetch()
Browse files Browse the repository at this point in the history
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 analogdevicesinc#84).

prefetch() has a memory reference for its argument.

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.

[ It seems in theory gcc 4.2 could miscompile this too; although no
  cases known.  In 2.6.24 we should probably switch to
  __builtin_prefetch() instead, but this is a simpler fix for now.
				-- AK ]

Signed-off-by: Serge Belyshev <[email protected]>
Signed-off-by: Andi Kleen <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ssb83 authored and Linus Torvalds committed Oct 5, 2007
1 parent 9cdcaa2 commit 4ecbca8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/asm-x86_64/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,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
Expand Down

0 comments on commit 4ecbca8

Please sign in to comment.