Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] casts in TLB macros
@ 2005-08-17  3:06 Andrew Isaacson
  2005-08-17 10:02 ` Maciej W. Rozycki
  2005-08-17 10:08 ` Ralf Baechle
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Isaacson @ 2005-08-17  3:06 UTC (permalink / raw)
  To: linux-mips

Fix three cases where macro arguments are not parenthesized, leading to
incorrect operator precedence when called with an expression as the
argument.  This causes incorrect evaluation of
    write_c0_entrylo0(pte_val(*ptep++) >> 6)
when pte_t is 64 bits - the pte value is cast to (unsigned int) first,
then the shift is done, losing the top 32 bits.

Also, this does not add an extra set of parentheses surrounding the
(cast)(value) pair, as there's no danger of precedence problems to avoid
given the high precedence of the cast operator and that this is the
terminal macro in this macro trail.

Signed-off-by: Andrew Isaacson <adi@broadcom.com>

 include/asm-mips/pgtable-32.h |    2 +-

Index: linux-2.6.13-rc5/include/asm-mips/mipsregs.h
===================================================================
--- linux-2.6.13-rc5.orig/include/asm-mips/mipsregs.h	2005-07-14 10:47:59.000000000 -0700
+++ linux-2.6.13-rc5/include/asm-mips/mipsregs.h	2005-08-16 19:44:47.000000000 -0700
@@ -693,13 +693,13 @@
 	if (sel == 0)							\
 		__asm__ __volatile__(					\
 			"mtc0\t%z0, " #register "\n\t"			\
-			: : "Jr" ((unsigned int)value));		\
+			: : "Jr" (unsigned int)(value));		\
 	else								\
 		__asm__ __volatile__(					\
 			".set\tmips32\n\t"				\
 			"mtc0\t%z0, " #register ", " #sel "\n\t"	\
 			".set\tmips0"					\
-			: : "Jr" ((unsigned int)value));		\
+			: : "Jr" (unsigned int)(value));		\
 } while (0)
 
 #define __write_64bit_c0_register(register, sel, value)			\
@@ -748,7 +748,7 @@
 do {									\
 	__asm__ __volatile__(						\
 		"ctc0\t%z0, " #register "\n\t"				\
-		: : "Jr" ((unsigned int)value));			\
+		: : "Jr" (unsigned int)(value));			\
 } while (0)
 
 /*

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

* Re: [PATCH] casts in TLB macros
  2005-08-17  3:06 [PATCH] casts in TLB macros Andrew Isaacson
@ 2005-08-17 10:02 ` Maciej W. Rozycki
  2005-08-17 10:08 ` Ralf Baechle
  1 sibling, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2005-08-17 10:02 UTC (permalink / raw)
  To: Andrew Isaacson; +Cc: linux-mips

On Tue, 16 Aug 2005, Andrew Isaacson wrote:

> @@ -748,7 +748,7 @@
>  do {									\
>  	__asm__ __volatile__(						\
>  		"ctc0\t%z0, " #register "\n\t"				\
> -		: : "Jr" ((unsigned int)value));			\
> +		: : "Jr" (unsigned int)(value));			\
>  } while (0)
>  
>  /*

 I'm surprised it works, but please don't drop the outer brackets in asm 
operands anyway.  Otherwise it's an obvious fix, thanks.

  Maciej

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

* Re: [PATCH] casts in TLB macros
  2005-08-17  3:06 [PATCH] casts in TLB macros Andrew Isaacson
  2005-08-17 10:02 ` Maciej W. Rozycki
@ 2005-08-17 10:08 ` Ralf Baechle
  2005-08-17 16:30   ` Andrew Isaacson
  1 sibling, 1 reply; 5+ messages in thread
From: Ralf Baechle @ 2005-08-17 10:08 UTC (permalink / raw)
  To: Andrew Isaacson; +Cc: linux-mips

On Tue, Aug 16, 2005 at 08:06:08PM -0700, Andrew Isaacson wrote:

> Fix three cases where macro arguments are not parenthesized, leading to
> incorrect operator precedence when called with an expression as the
> argument.  This causes incorrect evaluation of
>     write_c0_entrylo0(pte_val(*ptep++) >> 6)
> when pte_t is 64 bits - the pte value is cast to (unsigned int) first,
> then the shift is done, losing the top 32 bits.
> 
> Also, this does not add an extra set of parentheses surrounding the
> (cast)(value) pair, as there's no danger of precedence problems to avoid
> given the high precedence of the cast operator and that this is the
> terminal macro in this macro trail.

Thanks, applied,

  Ralf

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

* Re: [PATCH] casts in TLB macros
  2005-08-17 10:08 ` Ralf Baechle
@ 2005-08-17 16:30   ` Andrew Isaacson
  2005-08-17 16:44     ` Ralf Baechle
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Isaacson @ 2005-08-17 16:30 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On Wed, Aug 17, 2005 at 11:08:30AM +0100, Ralf Baechle wrote:
> On Tue, Aug 16, 2005 at 08:06:08PM -0700, Andrew Isaacson wrote:
> 
> > Fix three cases where macro arguments are not parenthesized, leading to
> > incorrect operator precedence when called with an expression as the
> > argument.  This causes incorrect evaluation of
> >     write_c0_entrylo0(pte_val(*ptep++) >> 6)
> > when pte_t is 64 bits - the pte value is cast to (unsigned int) first,
> > then the shift is done, losing the top 32 bits.
> > 
> > Also, this does not add an extra set of parentheses surrounding the
> > (cast)(value) pair, as there's no danger of precedence problems to avoid
> > given the high precedence of the cast operator and that this is the
> > terminal macro in this macro trail.
> 
> Thanks, applied,

Thank *you* for being smarter than me about the parenthesis...

(The patch I sent out was lacking the outer parens, and I used the
following plan for world domination:
1. notice problem, cut patch
2. go to dinner
3. test compile something unrelated by accident
4. send patch to mailing list
5. profit!)

-andy

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

* Re: [PATCH] casts in TLB macros
  2005-08-17 16:30   ` Andrew Isaacson
@ 2005-08-17 16:44     ` Ralf Baechle
  0 siblings, 0 replies; 5+ messages in thread
From: Ralf Baechle @ 2005-08-17 16:44 UTC (permalink / raw)
  To: Andrew Isaacson; +Cc: linux-mips

On Wed, Aug 17, 2005 at 09:30:02AM -0700, Andrew Isaacson wrote:

> (The patch I sent out was lacking the outer parens, and I used the
> following plan for world domination:
> 1. notice problem, cut patch
> 2. go to dinner
> 3. test compile something unrelated by accident
> 4. send patch to mailing list
> 5. profit!)

5) reminds me of Clausen Profit System Online, see
http://members.optusnet.com.au/clausen/profit/

  Ralf

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

end of thread, other threads:[~2005-08-17 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-17  3:06 [PATCH] casts in TLB macros Andrew Isaacson
2005-08-17 10:02 ` Maciej W. Rozycki
2005-08-17 10:08 ` Ralf Baechle
2005-08-17 16:30   ` Andrew Isaacson
2005-08-17 16:44     ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox