[PATCH 3/6] ARM: Emulate two-byte cmpxchg on ARMv6

From: Bradley Morgan

Date: Fri Sep 11 2026 - 15:30:59 EST


ARMv6 without the ARMv6K extensions, selected as CONFIG_CPU_V6,
has no ldrexh/strexh, so the __cmpxchg() switch only provides
case 1 through cmpxchg_emu_u8() and lets case 2 fall through to
__bad_cmpxchg(). Route case 2 through cmpxchg_emu_u16() so that
two-byte cmpxchg() works on these cores too.

ARMv6K and later already have native case 2 in the #else branch,
and __cmpxchg_local() already covers sizes 1 and 2 for ARMv6 via
__generic_cmpxchg_local(), so neither is touched.

Signed-off-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
---
arch/arm/include/asm/cmpxchg.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
index 9beb64d30586..6c0e2f21456b 100644
--- a/arch/arm/include/asm/cmpxchg.h
+++ b/arch/arm/include/asm/cmpxchg.h
@@ -167,6 +167,9 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
case 1:
oldval = cmpxchg_emu_u8((volatile u8 *)ptr, old, new);
break;
+ case 2:
+ oldval = cmpxchg_emu_u16((volatile u16 *)ptr, old, new);
+ break;
#else /* min ARCH > ARMv6 */
case 1:
do {
--
2.47.3