Skip to contentSkip to conversation

arm64: sysreg: Fix unprotected macro argmuent in write_sysreg

PATCH New Dave Martin 2 participants 3 messages Jul 25, 2017 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: sysreg: Fix unprotected macro argmuent in write_sysreg

write_sysreg() may misparse the value argument because it is used without parentheses to protect it.

This patch adds the ( ) in order to avoid any surprises.

---
 arch/arm64/include/asm/sysreg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +1 -1
index 16e44fa..822eebc 100644
@@ -492,7 +492,7 @@ asm(
  * the "%x0" template means XZR.
  */
 #define write_sysreg(v, r) do {					\
-	u64 __val = (u64)v;					\
+	u64 __val = (u64)(v);					\
 	asm volatile("msr " __stringify(r) ", %x0"		\
 		     : : "rZ" (__val));				\
 } while (0)
Signature · 1 line
2.1.4
reviewer
#1 lore raw

PATCH 1/1 arm64: sysreg: Fix unprotected macro argmuent in write_sysreg

Quoted 15 lines · Dave Martin

write_sysreg() may misparse the value argument because it is used without parentheses to protect it.

This patch adds the ( ) in order to avoid any surprises.

---
 arch/arm64/include/asm/sysreg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +0 -0
index 16e44fa..822eebc 100644

arch/arm64/include/asm/sysreg.h asm( · line 498

Quoted 8 lines
arch/arm64/include/asm/sysreg.h +1 -1
@@ -492,7 +492,7 @@ asm(
  * the "%x0" template means XZR.
  */
 #define write_sysreg(v, r) do {					\
-	u64 __val = (u64)v;					\
+	u64 __val = (u64)(v);					\
 	asm volatile("msr " __stringify(r) ", %x0"		\
 		     : : "rZ" (__val));				\
 } while (0)

Looks sensible.

It looks like write_sysreg_s() will need the same fixup; could you do that too?

With that:

Thanks,
Mark.

#2 lore raw

PATCH 1/1 arm64: sysreg: Fix unprotected macro argmuent in write_sysreg

Quoted 27 lines · Mark Rutland
Quoted 15 lines · Dave Martin

write_sysreg() may misparse the value argument because it is used without parentheses to protect it.

This patch adds the ( ) in order to avoid any surprises.

---
 arch/arm64/include/asm/sysreg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +0 -0
index 16e44fa..822eebc 100644

arch/arm64/include/asm/sysreg.h asm( · line 498

Quoted 8 lines
arch/arm64/include/asm/sysreg.h +1 -1
@@ -492,7 +492,7 @@ asm(
  * the "%x0" template means XZR.
  */
 #define write_sysreg(v, r) do {					\
-	u64 __val = (u64)v;					\
+	u64 __val = (u64)(v);					\
 	asm volatile("msr " __stringify(r) ", %x0"		\
 		     : : "rZ" (__val));				\
 } while (0)

Looks sensible.

Quoted 6 lines

It looks like write_sysreg_s() will need the same fixup; could you do that too?

With that:

Agreed, especially if somebody else does it...

Note that there are some

	write_sysreg(1 << n, SYS_FOO)

whose parse will be changed by this. However, n <= 30 in every case I've found, which should mean there is no change to the result -- i.e., (u64)((int)1 << n) == (u64)1 << n if n <= 30.

Cheers
---Dave