Skip to contentSkip to conversation

sh: cmpxchg: fix a bit shift bug in big_endian os

PATCH Superseded Pan Xinhui 3 participants 5 messages Apr 19, 2016 – Apr 26, 2016 SuperH

lore
Share & tools
lore

Pan Xinhui

author
#0 lore raw

PATCH 1/1 sh: cmpxchg: fix a bit shift bug in big_endian os

From: Pan Xinhui <[email protected]>

Correct bitoff in big endian OS.

Fixes 3226aad81aa6 ("sh: support 1 and 2 byte xchg")
---
 arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/include/asm/cmpxchg-xchg.h +1 -1
index 7219719..1e881f5 100644
@@ -21,7 +21,7 @@ static inline u32 __xchg_cmpxchg(volatile void *ptr, u32 x, int size)
 	int off = (unsigned long)ptr % sizeof(u32);
 	volatile u32 *p = ptr - off;
 #ifdef __BIG_ENDIAN
-	int bitoff = (sizeof(u32) - 1 - off) * BITS_PER_BYTE;
+	int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE;
 #else
 	int bitoff = off * BITS_PER_BYTE;
 #endif
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Pan Xinhui

From: Pan Xinhui <[email protected]>

Correct bitoff in big endian OS.

Fixes 3226aad81aa6 ("sh: support 1 and 2 byte xchg")

I would add: current code works correctly for 1 byte but not for 2 bytes.

Quoted 19 lines
---
 arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/include/asm/cmpxchg-xchg.h +1 -1
index 7219719..1e881f5 100644
@@ -21,7 +21,7 @@ static inline u32 __xchg_cmpxchg(volatile void *ptr, u32 x, int size)
 	int off = (unsigned long)ptr % sizeof(u32);
 	volatile u32 *p = ptr - off;
 #ifdef __BIG_ENDIAN
-	int bitoff = (sizeof(u32) - 1 - off) * BITS_PER_BYTE;
+	int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE;
 #else
 	int bitoff = off * BITS_PER_BYTE;
 #endif
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v2 1/1 sh: cmpxchg: fix a bit shift bug in big_endian os

In reply to Pan Xinhui

From: Pan Xinhui <[email protected]>

Correct bitoff in big endian OS.
Current code works correctly for 1 byte but not for 2 bytes.

Fixes 3226aad81aa6 ("sh: support 1 and 2 byte xchg")

---
changes from V1:
just add some patch comments. no code changes.

---
 arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/include/asm/cmpxchg-xchg.h +1 -1
index 7219719..1e881f5 100644
@@ -21,7 +21,7 @@ static inline u32 __xchg_cmpxchg(volatile void *ptr, u32 x, int size)
 	int off = (unsigned long)ptr % sizeof(u32);
 	volatile u32 *p = ptr - off;
 #ifdef __BIG_ENDIAN
-	int bitoff = (sizeof(u32) - 1 - off) * BITS_PER_BYTE;
+	int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE;
 #else
 	int bitoff = off * BITS_PER_BYTE;
 #endif
Signature · 1 line
1.9.1 
maintainer
#3 lore raw
Quoted 11 lines · Pan Xinhui

From: Pan Xinhui <[email protected]>

Correct bitoff in big endian OS.
Current code works correctly for 1 byte but not for 2 bytes.

Fixes 3226aad81aa6 ("sh: support 1 and 2 byte xchg")

---
changes from V1:
just add some patch comments. no code changes.

Looks good. Are you aware of any code affected by this bug that would make it a regression in 4.6? If so I'll try to get this in now as a bugfix; otherwise I'll include it in stuff for 4.7.

Rich

Quoted 19 lines
---
 arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/include/asm/cmpxchg-xchg.h +1 -1
index 7219719..1e881f5 100644
@@ -21,7 +21,7 @@ static inline u32 __xchg_cmpxchg(volatile void *ptr, u32 x, int size)
 	int off = (unsigned long)ptr % sizeof(u32);
 	volatile u32 *p = ptr - off;
 #ifdef __BIG_ENDIAN
-	int bitoff = (sizeof(u32) - 1 - off) * BITS_PER_BYTE;
+	int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE;
 #else
 	int bitoff = off * BITS_PER_BYTE;
 #endif
Signature · 1 line
1.9.1 
author
#4 lore raw
Quoted 13 lines · Rich Felker
Quoted 11 lines · Pan Xinhui

From: Pan Xinhui <[email protected]>

Correct bitoff in big endian OS.
Current code works correctly for 1 byte but not for 2 bytes.

Fixes 3226aad81aa6 ("sh: support 1 and 2 byte xchg")

---
changes from V1:
just add some patch comments. no code changes.

Quoted 4 lines

Looks good. Are you aware of any code affected by this bug that would make it a regression in 4.6? If so I'll try to get this in now as a bugfix; otherwise I'll include it in stuff for 4.7.

no idea about what code is affected.
4.7 is okay I think. :)

xinhui

Quoted 23 lines

Rich

Quoted 19 lines
---
 arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/include/asm/cmpxchg-xchg.h +1 -1
index 7219719..1e881f5 100644
@@ -21,7 +21,7 @@ static inline u32 __xchg_cmpxchg(volatile void *ptr, u32 x, int size)
 	int off = (unsigned long)ptr % sizeof(u32);
 	volatile u32 *p = ptr - off;
 #ifdef __BIG_ENDIAN
-	int bitoff = (sizeof(u32) - 1 - off) * BITS_PER_BYTE;
+	int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE;
 #else
 	int bitoff = off * BITS_PER_BYTE;
 #endif
Signature · 1 line
1.9.1