Re: [PATCH] sh: cmpxchg: fix a bit shift bug in big_endian os

From: Michael S. Tsirkin
Date: Tue Apr 19 2016 - 06:00:49 EST


On Tue, Apr 19, 2016 at 02:58:53PM +0800, Pan Xinhui wrote:
> From: Pan Xinhui <xinhui.pan@xxxxxxxxxxxxxxxxxx>
>
> Correct bitoff in big endian OS.
>
> Fixes: 3226aad81aa6 ("sh: support 1 and 2 byte xchg")
> Signed-off-by: Pan Xinhui <xinhui.pan@xxxxxxxxxxxxxxxxxx>

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

Acked-by: Michael S. Tsirkin <mst@xxxxxxxxxx>

> ---
> arch/sh/include/asm/cmpxchg-xchg.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/sh/include/asm/cmpxchg-xchg.h b/arch/sh/include/asm/cmpxchg-xchg.h
> index 7219719..1e881f5 100644
> --- a/arch/sh/include/asm/cmpxchg-xchg.h
> +++ b/arch/sh/include/asm/cmpxchg-xchg.h
> @@ -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
> --
> 1.9.1