[RFC PATCH v1 5/5] locking/atomic: xtensa: Refactor xchg_small to use atomic_fetch_and_or

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: wangrui <wangrui@xxxxxxxxxxx>

Signed-by-off: Rui Wang <wangrui@xxxxxxxxxxx>
Signed-by-off: hev <r@xxxxxx>
---
 arch/xtensa/include/asm/cmpxchg.h | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h
index 3699e2818efb..e118cfc00988 100644
--- a/arch/xtensa/include/asm/cmpxchg.h
+++ b/arch/xtensa/include/asm/cmpxchg.h
@@ -182,16 +182,10 @@ static inline u32 xchg_small(volatile void *ptr, u32 x, int size)
 	int bitoff = off * BITS_PER_BYTE;
 #endif
 	u32 bitmask = ((0x1 << size * BITS_PER_BYTE) - 1) << bitoff;
-	u32 oldv, newv;
-	u32 ret;
+	u32 oldv;
 
-	do {
-		oldv = READ_ONCE(*p);
-		ret = (oldv & bitmask) >> bitoff;
-		newv = (oldv & ~bitmask) | (x << bitoff);
-	} while (__cmpxchg_u32(p, oldv, newv) != oldv);
-
-	return ret;
+	oldv = atomic_fetch_and_or(p, ~bitmask, x << bitoff);
+	return (oldv & bitmask) >> bitoff;
 }
 
 /*
-- 
2.32.0




[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux