linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Protect prefetch macro arguments.
@ 2010-03-26 20:44 David Daney
  2010-03-26 21:04 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: David Daney @ 2010-03-26 20:44 UTC (permalink / raw)
  To: torvalds, akpm; +Cc: linux-kernel, linux-arch, David Daney

The GCC built-in __builtin_prefetch() is a vargs function.  If we
don't wrap the macro parameter in parentheses, a comma operator in the
actual argument list might cause unintended parameters to be passed to
__builtin_prefetch().

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---
 include/linux/prefetch.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/prefetch.h b/include/linux/prefetch.h
index af7c36a..6179433 100644
--- a/include/linux/prefetch.h
+++ b/include/linux/prefetch.h
@@ -35,11 +35,11 @@
 */
 
 #ifndef ARCH_HAS_PREFETCH
-#define prefetch(x) __builtin_prefetch(x)
+#define prefetch(x) __builtin_prefetch((x))
 #endif
 
 #ifndef ARCH_HAS_PREFETCHW
-#define prefetchw(x) __builtin_prefetch(x,1)
+#define prefetchw(x) __builtin_prefetch((x), 1)
 #endif
 
 #ifndef ARCH_HAS_SPINLOCK_PREFETCH
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Protect prefetch macro arguments.
  2010-03-26 20:44 [PATCH] Protect prefetch macro arguments David Daney
@ 2010-03-26 21:04 ` Linus Torvalds
  2010-03-26 21:18   ` David Daney
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2010-03-26 21:04 UTC (permalink / raw)
  To: David Daney; +Cc: akpm, linux-kernel, linux-arch



On Fri, 26 Mar 2010, David Daney wrote:
>
> The GCC built-in __builtin_prefetch() is a vargs function.  If we
> don't wrap the macro parameter in parentheses, a comma operator in the
> actual argument list might cause unintended parameters to be passed to
> __builtin_prefetch().

This seems totally pointless and actively wrong.

You cannot have a comma operator in the actual argument list to the 
#define, because if you did, then you'd get a

	macro "prefetch()" passed 2 arguments, but takes just 1

so the only way I see to pass a comma operator is to _already_ have the 
macro parameter in parenthesis.

		Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Protect prefetch macro arguments.
  2010-03-26 21:04 ` Linus Torvalds
@ 2010-03-26 21:18   ` David Daney
  2010-03-26 21:23     ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: David Daney @ 2010-03-26 21:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: akpm, linux-kernel, linux-arch

On 03/26/2010 02:04 PM, Linus Torvalds wrote:
>
>
> On Fri, 26 Mar 2010, David Daney wrote:
>>
>> The GCC built-in __builtin_prefetch() is a vargs function.  If we
>> don't wrap the macro parameter in parentheses, a comma operator in the
>> actual argument list might cause unintended parameters to be passed to
>> __builtin_prefetch().
>
> This seems totally pointless and actively wrong.

Pointless, perhaps.  But 'actively wrong'?  Are you sure about that?

In any event I guess I don't care much one way or the other.  I was 
working on something else when I saw this. It looked wrong to me.

Thanks,
David Daney


>
> You cannot have a comma operator in the actual argument list to the
> #define, because if you did, then you'd get a
>
> 	macro "prefetch()" passed 2 arguments, but takes just 1
>
> so the only way I see to pass a comma operator is to _already_ have the
> macro parameter in parenthesis.
>
> 		Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Protect prefetch macro arguments.
  2010-03-26 21:18   ` David Daney
@ 2010-03-26 21:23     ` Linus Torvalds
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2010-03-26 21:23 UTC (permalink / raw)
  To: David Daney; +Cc: akpm, linux-kernel, linux-arch



On Fri, 26 Mar 2010, David Daney wrote:

> On 03/26/2010 02:04 PM, Linus Torvalds wrote:
> > 
> > 
> > On Fri, 26 Mar 2010, David Daney wrote:
> > > 
> > > The GCC built-in __builtin_prefetch() is a vargs function.  If we
> > > don't wrap the macro parameter in parentheses, a comma operator in the
> > > actual argument list might cause unintended parameters to be passed to
> > > __builtin_prefetch().
> > 
> > This seems totally pointless and actively wrong.
> 
> Pointless, perhaps.  But 'actively wrong'?  Are you sure about that?

Yes, I'm sure about that.

Your commit message was actively misleading, and the end result is worse 
than the original and shows a lack of understanding of the C preprocessor. 

IOW, very much "actively wrong".

		Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-26 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26 20:44 [PATCH] Protect prefetch macro arguments David Daney
2010-03-26 21:04 ` Linus Torvalds
2010-03-26 21:18   ` David Daney
2010-03-26 21:23     ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).