From nobody Thu Sep 24 15:10:10 2026 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEB0B3F4DCF; Tue, 22 Sep 2026 17:33:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098442; cv=none; b=KjIXc/2b5hWWu5FdNoWaq985gMx3Hs0GfIlnBB8hiprJhFbj5LTfNJPSMgywsNR6YEfiwwomPl4Ova7En4UzvnpJjNg1AvjMUeZAkkZPRRVHK4JzQ3SpyGcukHOtcxIN0Fwk5aXqUk4feLKFwTLYzMaKrpLzsptZKarsflmkOBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098442; c=relaxed/simple; bh=tj8w7ebEnGPP79+CKZSn3qeBQgQyB3e7XLykP6i6aWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JfT46C4ZV0qOjAb22ndAAy++uc7zM8wCzylq1pw/njx5J94WeXaXCPdb1Lc+8uJfJ8BlK0h2LyyripUctNaC4R5BbVovrDsmnqDXCce2myyJGHpZeKviA5wOzB+HX9FUxpOY+qY3gfcc94qWLYPcHM/UdYHMIBuXsqJb+JoGo+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=I+lrooYe; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=4B5H3lLT; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="I+lrooYe"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="4B5H3lLT" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098433; bh=DV+S+YBKPI4yE6gLNe9ePuD 8ye5fzLkcyxtpk3kLyU4=; b=I+lrooYevbZ0Tg8wkwIQhM91+vocihHYqHNTDYx4RtT7Jzn+Ql hZHU1EvQtFSJbjslt+jQcMA3pkiqZgtY1lSg5wC1NgqOSdPcteG5NkGT9Jd3DrZAWhbGSes+sps PpMPMWm0S+UfEmdhb3RpLeq+uinPXUfDP/WMraaWx2FMerxCAdHZr14XhPcI+1972Hbsp1yC0dn 41bYsWbwKKEf0w/lV7UhJ3vKXO8kwuTkTbNKZ71MjjadOEGuVP2F+90xjGHT1R94MDb381fGTSm 3Rkt7Vc0362w8w7LcJVsymGaD8ezU+0pQ36VJrJCZGuuOmw+K0NKtHLnh2tijmHS0tg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098433; bh=DV+S+YBKPI4yE6gLNe9ePuD 8ye5fzLkcyxtpk3kLyU4=; b=4B5H3lLTqQQDDZX/g8Fy3eGlTbWYmcr09GJ/Ki1qMnDbpF9pch CydZm/GlGh6JsTty1EOWo0x5k7DfHD9O2bAA==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 1/5] lib: Add two-byte cmpxchg emulation function Date: Tue, 22 Sep 2026 17:33:50 +0000 Message-ID: <20260922173354.14404-2-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cmpxchg_emu_u8() emulates one-byte cmpxchg() in terms of four-byte cmpxchg() for the architectures lacking native one-byte atomics. The same architectures also lack native two-byte cmpxchg(), where such an operation is not supported and either fails to compile via BUILD_BUG() or fails to link, because the bad pointer sentinels these architectures declare are never defined. Add cmpxchg_emu_u16(), the two-byte sibling. It reads the enclosing word with READ_ONCE(), splices the two target bytes through a union and loops on cmpxchg() of the full word until the compare succeeds. Like cmpxchg_emu_u8() it is fully ordered. Unlike cmpxchg_emu_u8() it casts the old and new values to u16 internally and returns unsigned long, taking the old and new values as unsigned long, per the suggestion from David Laight. The switch statements in the architecture macros instantiate every size case, so a cmpxchg() on a pointer type checks the two-byte case as well, and a u16 parameter or return would make the macro casts and return conversions warn there. With unsigned long parameters and return the call sites need no narrowing casts, pointer exchanges compile warning free, and the function still compares and returns exactly the 16 bits the caller asked for, which matches the hardware cmpxchg r16 behaviour where a 16-bit compare only looks at the low 16 bits of the register. cmpxchg_emu_u8() keeps returning the old value unmasked, so a caller that passes a wider old than 8 bits still gets it back as passed, matching the behaviour the one-byte emulator always had. The Kconfig symbol gating this file is renamed from ARCH_NEED_CMPXCHG_1_EMU to ARCH_NEED_CMPXCHG_1_2_EMU, as it now selects both the one-byte and the two-byte emulation. Suggested-by: Paul E. McKenney Suggested-by: David Laight Signed-off-by: Bradley Morgan Reviewed-by: David Laight Reviewed-by: Paul E. McKenney --- arch/Kconfig | 2 +- arch/arc/Kconfig | 2 +- arch/csky/Kconfig | 2 +- arch/sh/Kconfig | 2 +- arch/xtensa/Kconfig | 2 +- include/linux/cmpxchg-emu.h | 4 +++- lib/Makefile | 2 +- lib/cmpxchg-emu.c | 38 +++++++++++++++++++++++++++++++++---- 8 files changed, 43 insertions(+), 11 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 3bb2e568f5b1..d56064797e09 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1817,7 +1817,7 @@ config CC_HAS_SANE_FUNCTION_ALIGNMENT # strict alignment always, even with -falign-functions. def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG =20 -config ARCH_NEED_CMPXCHG_1_EMU +config ARCH_NEED_CMPXCHG_1_2_EMU bool =20 config ARCH_WANTS_PRE_LINK_VMLINUX diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 80e61175bf52..0e91d254eccb 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -14,7 +14,7 @@ config ARC select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE - select ARCH_NEED_CMPXCHG_1_EMU + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC select ARCH_32BIT_OFF_T select BUILDTIME_TABLE_SORT diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig index 4331313a42ff..5f26e8615d7d 100644 --- a/arch/csky/Kconfig +++ b/arch/csky/Kconfig @@ -37,7 +37,7 @@ config CSKY select ARCH_INLINE_SPIN_UNLOCK_BH if !PREEMPTION select ARCH_INLINE_SPIN_UNLOCK_IRQ if !PREEMPTION select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPTION - select ARCH_NEED_CMPXCHG_1_EMU + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace) select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select COMMON_CLK diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index d60f1d5a94c0..09e556fced01 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -14,7 +14,7 @@ config SUPERH select ARCH_HIBERNATION_POSSIBLE if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION - select ARCH_NEED_CMPXCHG_1_EMU + select ARCH_NEED_CMPXCHG_1_2_EMU select CPU_NO_EFFICIENT_FFS select DMA_DECLARE_COHERENT select GENERIC_ATOMIC64 diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index f2f9cd9cde50..62019fd444d4 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -14,7 +14,7 @@ config XTENSA select ARCH_HAS_DMA_SET_UNCACHED if MMU select ARCH_HAS_STRNCPY_FROM_USER if !KASAN select ARCH_HAS_STRNLEN_USER - select ARCH_NEED_CMPXCHG_1_EMU + select ARCH_NEED_CMPXCHG_1_2_EMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS diff --git a/include/linux/cmpxchg-emu.h b/include/linux/cmpxchg-emu.h index 998deec67740..2db70f1e3925 100644 --- a/include/linux/cmpxchg-emu.h +++ b/include/linux/cmpxchg-emu.h @@ -4,12 +4,14 @@ * lacking direct support for these sizes. These are implemented in terms * of 4-byte cmpxchg operations. * - * Copyright (C) 2024 Paul E. McKenney. + * Copyright (C) 2024 Paul E. McKenney + * Copyright (C) 2026 Bradley Morgan */ =20 #ifndef __LINUX_CMPXCHG_EMU_H #define __LINUX_CMPXCHG_EMU_H =20 uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); +unsigned long cmpxchg_emu_u16(volatile u16 *p, unsigned long old, unsigned= long new); =20 #endif /* __LINUX_CMPXCHG_EMU_H */ diff --git a/lib/Makefile b/lib/Makefile index 43421c39d21b..d0e69312176a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -202,7 +202,7 @@ obj-$(CONFIG_CODE_TAGGING) +=3D codetag.o lib-$(CONFIG_GENERIC_BUG) +=3D bug.o =20 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) +=3D syscall.o -obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_EMU) +=3D cmpxchg-emu.o +obj-$(CONFIG_ARCH_NEED_CMPXCHG_1_2_EMU) +=3D cmpxchg-emu.o =20 obj-$(CONFIG_DYNAMIC_DEBUG_CORE) +=3D dynamic_debug.o #ensure exported functions have prototypes diff --git a/lib/cmpxchg-emu.c b/lib/cmpxchg-emu.c index 27f6f97cb60d..25c69224a759 100644 --- a/lib/cmpxchg-emu.c +++ b/lib/cmpxchg-emu.c @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Emulated 1-byte cmpxchg operation for architectures lacking direct - * support for this size. This is implemented in terms of 4-byte cmpxchg - * operations. + * Emulated 1-byte and 2-byte cmpxchg operations for architectures lacking + * direct support for these sizes. These are implemented in terms of + * 4-byte cmpxchg operations. * - * Copyright (C) 2024 Paul E. McKenney. + * Copyright (C) 2024 Paul E. McKenney + * Copyright (C) 2026 Bradley Morgan */ =20 #include @@ -43,3 +44,32 @@ uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, = uintptr_t new) return old; } EXPORT_SYMBOL_GPL(cmpxchg_emu_u8); + +union u16_32 { + u16 h[2]; + u32 w; +}; + +/* Emulate two-byte cmpxchg() in terms of 4-byte cmpxchg. */ +unsigned long cmpxchg_emu_u16(volatile u16 *p, unsigned long old, unsigned= long new) +{ + u32 *p32 =3D (u32 *)(((uintptr_t)p) & ~0x3); + int i =3D (((uintptr_t)p) & 0x2) / 2; + union u16_32 old32; + union u16_32 new32; + u32 ret; + + WARN_ON_ONCE(((uintptr_t)p) & 0x1); + ret =3D READ_ONCE(*p32); + do { + old32.w =3D ret; + if (old32.h[i] !=3D (u16)old) + return (unsigned long)old32.h[i]; + new32.w =3D old32.w; + new32.h[i] =3D (u16)new; + instrument_atomic_read_write(p, 2); + ret =3D data_race(cmpxchg(p32, old32.w, new32.w)); // Overridden above. + } while (ret !=3D old32.w); + return (u16)old; +} +EXPORT_SYMBOL_GPL(cmpxchg_emu_u16); --=20 2.47.3 From nobody Thu Sep 24 15:10:10 2026 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8397F49363D; Tue, 22 Sep 2026 17:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098587; cv=none; b=Vre7Meq1a7VA10PFCxXNnQ6Yfjj+UPeDV3aX9vTD8LG9Jm+qiSOowK8YEz87rbubs4KtITDeP4S+zZvv0+cgJKoWTyNAO4yQcBZ5C6oEGyEct28G3YZkYlflaxIMAGpx05NEindigunnifP1BbA87V7J4xvCRvnUn0VkXoD57Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098587; c=relaxed/simple; bh=G2I/oBZTdGkJuNPKCx3yROTpE+54jzzqW7V8gwCHaF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HL2jnIJiP2khNdi4vM7ZZ3tAH263K04pETgp1rOxSgwZXVPeNDksU7nhTfZJlbt7pTr8njSnZ6Q3EeAJshzrvqKtKlCkL7uvtgkJx1crHThnsj+E5LvUoV8EaE83gI1wIAeECWeS1h7U8fo1/EhZqQ6y51mGVl4pjKjh7SPUlQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=RgdRjyED; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=54xM5N6K; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="RgdRjyED"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="54xM5N6K" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=e1GcMnqFLCYDoymp6RLJVeb pmtQeo9UYDw7sYBJUhCo=; b=RgdRjyEDbXNkMPQ8KeUZHOgR41025YtvXpBr9YubcWfvfFrTkH WsjQGi5iKF0/Q7SxfbLq32+CVgwtchQ06SJ5gzIcpi3WGrBxvO4s7NUL6vMe+4bJHUqRhxoD10/ 67IJY2fFgPoeyXd+/kWcUxSXjv/IgzHlouVSWVrT1b3BW0UFuKz9A1hVjASVqQVX0V/Qvbd0fH8 vHRo8tBFCz/m8QLnTFlKT9PwzfrH5lMW1uOW2QIl5C5/zUZBuVD/2HZxGFpv6GNPma2OJu/CpKj 7q8LI2RexEJBTUq92MqDBL7Vr+uaH85fX/bcVlapDaVsVUx7mXpsTMIIheGpxXR1AhQ==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=e1GcMnqFLCYDoymp6RLJVeb pmtQeo9UYDw7sYBJUhCo=; b=54xM5N6KOQWLgmVo6u80leBEDQVMX+gYb8ekcXt6NwZL2Szwo1 LHYwY7CewossBjldsNDBthMIOpoIFgYd7dDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 2/5] ARC: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:51 +0000 Message-ID: <20260922173354.14404-3-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ARC has no two-byte atomic compare and swap, so the arch_cmpxchg_relaxed() macro switch lets case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long and narrows them itself, so the (uintptr_t) casts on _o_ and _n_ are no longer needed and the case 2 call passes them straight. The switch also now tests sizeof(*(_p_)) instead of sizeof((_p_)), which switched on the pointer and made the size 1 and size 2 cases dead code, routing every sub-word cmpxchg() through the 32-bit llock/scond pair and comparing whole words against sub-word values, so the compare almost never succeeded. The old and new values are now declared as unsigned long through (unsigned long)(0 ? *(_p_) : (old)), the idiom David Laight suggested, which type checks the arguments against the pointee, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan Reviewed-by: David Laight Reviewed-by: Paul E. McKenney --- arch/arc/include/asm/cmpxchg.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index 76f43db0890f..4596edfefa95 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -42,16 +42,19 @@ #define arch_cmpxchg_relaxed(ptr, old, new) \ ({ \ __typeof__(ptr) _p_ =3D (ptr); \ - __typeof__(*(ptr)) _o_ =3D (old); \ - __typeof__(*(ptr)) _n_ =3D (new); \ + unsigned long _old_ =3D (unsigned long)(0 ? *(_p_) : (old)); \ + unsigned long _new_ =3D (unsigned long)(0 ? *(_p_) : (new)); \ __typeof__(*(ptr)) _prev_; \ \ - switch(sizeof((_p_))) { \ + switch (sizeof(*(_p_))) { \ case 1: \ - _prev_ =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_,= (uintptr_t)_o_, (uintptr_t)_n_); \ + _prev_ =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_,= _old_, _new_); \ + break; \ + case 2: \ + _prev_ =3D (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *__force)_p= _, _old_, _new_); \ break; \ case 4: \ - _prev_ =3D __cmpxchg(_p_, _o_, _n_); \ + _prev_ =3D (__typeof__(*(ptr)))__cmpxchg(_p_, _old_, _new_); \ break; \ default: \ BUILD_BUG(); \ @@ -64,8 +67,8 @@ #define arch_cmpxchg(ptr, old, new) \ ({ \ volatile __typeof__(ptr) _p_ =3D (ptr); \ - __typeof__(*(ptr)) _o_ =3D (old); \ - __typeof__(*(ptr)) _n_ =3D (new); \ + unsigned long _old_ =3D (unsigned long)(0 ? *(_p_) : (old)); \ + unsigned long _new_ =3D (unsigned long)(0 ? *(_p_) : (new)); \ __typeof__(*(ptr)) _prev_; \ unsigned long __flags; \ \ @@ -102,7 +105,7 @@ __typeof__(ptr) _p_ =3D (ptr); \ __typeof__(*(ptr)) _val_ =3D (val); \ \ - switch(sizeof(*(_p_))) { \ + switch (sizeof(*(_p_))) { \ case 4: \ _val_ =3D __arch_xchg(_p_, _val_); \ break; \ --=20 2.47.3 From nobody Thu Sep 24 15:10:10 2026 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E30254DAE6; Tue, 22 Sep 2026 17:36:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098576; cv=none; b=b3UsdDr4X/kFev1VR0ZVclwSXxTBT0umam29/Ixg4mO6byoP3r0fg+2pKkbI5vNwOTfc95R8o5YmxYhfExQK4TKu/loXIxDrbpj2Dd+CrWkB+m5IPNDCJ5s2/WzvyKUgGcxsKWJYLjtutKjIuSLimVjlpX2WSCF+S9Q/Ky6rfB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098576; c=relaxed/simple; bh=yQbHi2/qjWQm7R28Ag7bKayxGrtMhrNYW+yci+1KRH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M9iTwG5vvOkcuXP9BBXDFGVNIhqcM1J8PAWzMusf7pZizq5i0AH0h5hIpRgdfSip2zsTrm6YoUyGIAKC3uh9VnF6rlUzIOHvtatCKiCl7rtw7uq3PzEkPw1WU9VPAzWyYu6rRn9X4Lbfm2M19GXd314LkciKj8LM/yn3i+Pqob0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=bZ38dyWM; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=jnZiJ1Qj; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="bZ38dyWM"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="jnZiJ1Qj" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=bZ38dyWMgd/G/6OMhHggQwAi2Id4aT8IYufucK56A4wyGw4Iuj z2W5xwZGeASaGF/HHJf8ssq8z4PoylGq2B1t7R6ut/d8M3Ij2LG7BjwOviGy/uB0NVYDwscv1JD 7kPkG1IQ6VVkHrlLt2lYDSGuvhjweGzQg3VXOPDtMA2RsQ6UWzausKwtTWqfJRhvMcA8RRPQNtO HTqLo1bFm7LJUzrUzxCrKuZJYb59yJZr/yDqMsOFU2kNCNhtPy0g0jAdHqhHquweKOujEeL+pJ4 vuncC6fMYzfNZrwUChfQxtVt+ggSqaj/oGkEp0xUGYy7/Zp9Vf17BnKlLL2u3mAWDOQ==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098434; bh=ghYvDCJ6wWgl/DWKvRlZLjc r4JmsCO6Diem7VtlYvoo=; b=jnZiJ1QjwuyC2NRhs59khGUE4Z66oJnKO75veJ4E/0hcaljPvm ulv9bbDDiHprbgM5vKUmZm0jYzB24CcBNCDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 3/5] sh: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:52 +0000 Message-ID: <20260922173354.14404-4-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SH has no byte or halfword atomic memory operations, so the __cmpxchg() switch routes case 1 through cmpxchg_emu_u8() and lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() fails at link time. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (unsigned long) casts move off the call and into _old_ and _new_ declarations that type check the old and new arguments against *ptr through (unsigned long)(0 ? *ptr : _o_), the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer compiles silently. Acked-by: John Paul Adrian Glaubitz Signed-off-by: Bradley Morgan Reviewed-by: David Laight Reviewed-by: Paul E. McKenney --- arch/sh/include/asm/cmpxchg.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h index 1e5dc5ccf7bf..b87f59107b4e 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -59,6 +59,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr= , unsigned long old, switch (size) { case 1: return cmpxchg_emu_u8(ptr, old, new); + case 2: + return cmpxchg_emu_u16(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); } @@ -70,8 +72,10 @@ static inline unsigned long __cmpxchg(volatile void * pt= r, unsigned long old, ({ \ __typeof__(*(ptr)) _o_ =3D (o); \ __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ - (unsigned long)_n_, sizeof(*(ptr))); \ + unsigned long _old_ =3D (unsigned long)(0 ? *ptr : _o_); \ + unsigned long _new_ =3D (unsigned long)(0 ? *ptr : _n_); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), _old_, \ + _new_, sizeof(*(ptr))); \ }) =20 #include --=20 2.47.3 From nobody Thu Sep 24 15:10:10 2026 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89219560ADD; Tue, 22 Sep 2026 17:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098581; cv=none; b=vF+s6t8Nyx6W3r+XN79fEBZI4wWFis1vwe2/WD0JH+dZ0JFpjtCSqj0vYcqZ0aNIzm/q+U7EU+gU4Crgk1+mc+9ymu9n06uQtmCDxpkzHZD7vj7prft02BBk8tUdxZTn2/KxyLo/67wBS07kbyNZfynPLSOMy2rS5e+QaeUN12o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098581; c=relaxed/simple; bh=NIprbG5WL6OpMAMxOPQrRQbIc6U5xN2vwQ5+5CySqcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NHYqkaabqCSEi/Ph6dgLORZnUWvWusg7vIdVE6hlCzXkOD6h5OJeeDHKJsUS7JjPozE2gn3HS4mWIsp2Jd8MMBF9xeGZjyn7+qh1lc/sb4Wz5jVe+Jp6Hj9ebkyAbrn2b42rsBYmUxcTx3Buq3I5BiKiUMClhsFd6ZGPPNIpJ6Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=A5/0/GOU; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=NTp5knoE; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="A5/0/GOU"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="NTp5knoE" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=wl+BtXFs/QJChJ/sOKgC86/ HKj3R5tfPpUhFH8oo0uc=; b=A5/0/GOUc+WvYs825/8ouOL1uBIBkqo06ZEzHpL/pV7+uEtN+b Q06RZe/uHEgOY77Uzlh5dL9QmnGwW+2nv5v1qBCVhyXNv4T8Uqdv2Yfcc8ENtyEoImQM/c7WOV8 YCs2e5QkHGlXhMJ+H5KckshFL2DoJqgx/era/7X5JIkCE0YBZeMvl+Q038j/sHyXO00VCzyFPGm kc2VoX6bR2Tw+Kt1LeLRBtpqbrdpVvVDQOuAsb8j2YgHfW4NrjXkxLnF+rgsXf3dHDeuCOwIYmb gNlbihmQLhGtzbM0wf1poT0eIdtdfFePxhoQW+obXpIAfDOsR7EGFDT9B2A5+J/SlVg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=wl+BtXFs/QJChJ/sOKgC86/ HKj3R5tfPpUhFH8oo0uc=; b=NTp5knoEnFR7JN5OFPhBFH1QY9WSnU+vHpvP8lpWk2ed+OsGcb 0/J3nRC2j+Rb5PnC8PsP8xBvuryNvrIOpqBQ==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 4/5] csky: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:53 +0000 Message-ID: <20260922173354.14404-5-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" C-SKY has no two-byte atomic compare and swap, so the __cmpxchg() macros let case 2 fall through to BUILD_BUG() via default. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (uintptr_t) casts on __old and __new are no longer needed and the case 2 call passes them straight. The old and new values are declared as unsigned long through (unsigned long)(0 ? *(ptr) : (old)), the idiom David Laight suggested, which type checks the arguments against the pointee, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan Reviewed-by: David Laight Reviewed-by: Paul E. McKenney --- arch/csky/include/asm/cmpxchg.h | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxch= g.h index db6dda47184e..29dc56e4b7f1 100644 --- a/arch/csky/include/asm/cmpxchg.h +++ b/arch/csky/include/asm/cmpxchg.h @@ -57,13 +57,16 @@ #define __cmpxchg_relaxed(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old =3D (old); \ + unsigned long __old =3D (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new =3D (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old= , __new); \ + break; \ + case 2: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __o= ld, __new); \ break; \ case 4: \ asm volatile ( \ @@ -90,13 +93,16 @@ #define __cmpxchg_acquire(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old =3D (old); \ + unsigned long __old =3D (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new =3D (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old= , __new); \ + break; \ + case 2: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __o= ld, __new); \ break; \ case 4: \ asm volatile ( \ @@ -124,13 +130,16 @@ #define __cmpxchg(ptr, old, new, size) \ ({ \ __typeof__(ptr) __ptr =3D (ptr); \ - __typeof__(new) __new =3D (new); \ - __typeof__(new) __tmp; \ - __typeof__(old) __old =3D (old); \ + unsigned long __old =3D (unsigned long)(0 ? *(ptr) : (old)); \ + unsigned long __new =3D (unsigned long)(0 ? *(ptr) : (new)); \ + unsigned long __tmp; \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 1: \ - __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uint= ptr_t)__old, (uintptr_t)__new); \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, __old= , __new); \ + break; \ + case 2: \ + __ret =3D (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, __o= ld, __new); \ break; \ case 4: \ asm volatile ( \ --=20 2.47.3 From nobody Thu Sep 24 15:10:10 2026 Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55954563FC3; Tue, 22 Sep 2026 17:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.75.144.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098590; cv=none; b=kM+2BwmlFODQryA0grLh1xd3dnVIGQOuQZxoMjBSbypJzdgvn5oss2vRHc8GC7m0hy+afnhmA2op1+XyT2Fl7OOWrq5GDxvArZCVL7qAme3dOw7NHA4yAgHRAgn1yUsVMuiDrbANMhgFFIjs2baLjlEHQ4w+SgumjNAvvrDYIcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790098590; c=relaxed/simple; bh=Zzf1rbgihCrOyP1/qqfesaFc+2OZGZF5hAiHzrg6Xrs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+oQ1CsNpwq9K+dHgN5k39hua2+QdCX89T8h3uT9UF5lQXye0o4yvFjzpjPiMmcaZOnToLcMnRgopvokTwtGPKQgCJlPt/wght4brj7O1jmECFk5tQaMOKm4xAen0O2pW5xGk15WecowjV8jnkShm51mxqYuuFuePaQFKtfrDdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org; spf=pass smtp.mailfrom=mainlining.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=hxyhNKhp; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b=mIt3IqqS; arc=none smtp.client-ip=5.75.144.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mainlining.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mainlining.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="hxyhNKhp"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="mIt3IqqS" DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=4wVfAlEcovYJiLRAiW1UExN eq/b3xEK1OUjxcP/7QYQ=; b=hxyhNKhpHnG4LHB+IQytsfxPMEf6YigYhmBGZ6P1fc8JdTpofF 6/G3CK5eZbESW1khN3Oxuk3tTVRtyjIbZxXm7V/HRQMWqDGh17DVaXZRIj+dplFovWqMFx6Qd/N HYEuhDiGM8wwpRWslxqJozCj/owYlqjVph49yfKRkBOvKGP/olaRr80OLt3TX6jlUFhNPfXQASk UQuRL00HYhzZ/jl7YWoEfFoMh0jYwokqxLaO14TRt4zS0R4tL5JIgaJwdbMzvfPphucuTBMnKFP jjNQE9iV8ZIxOPszyZmfCQkHSxGLynC1RjC3MsaMYSL/3LD5RIP4ZC1boH5HOoZSaVw==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1790098435; bh=4wVfAlEcovYJiLRAiW1UExN eq/b3xEK1OUjxcP/7QYQ=; b=mIt3IqqSgxeINDfPOkt7tdWMzH4kExoyXkiMgmIYJl8N/S4dZ9 2BgUIRlcxsvR2j6OPj3KfJzB0NPulRzvSkDg==; From: Bradley Morgan To: Andrew Morton , Vineet Gupta , Guo Ren , Yoshinori Sato , Rich Felker , Chris Zankel , Max Filippov Cc: Arnd Bergmann , "Paul E . McKenney" , David Laight , John Paul Adrian Glaubitz , linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH 5/5] xtensa: Emulate two-byte cmpxchg Date: Tue, 22 Sep 2026 17:33:54 +0000 Message-ID: <20260922173354.14404-6-brads@mainlining.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922173354.14404-1-brads@mainlining.org> References: <20260922173354.14404-1-brads@mainlining.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Xtensa has no two-byte atomic compare and swap, so the __cmpxchg() switch lets case 2 fall through to __cmpxchg_called_with_bad_pointer(), which is declared but never defined, so a two-byte cmpxchg() fails at link time. Route case 2 through the new cmpxchg_emu_u16(), which takes the old and new values as unsigned long, so the (unsigned long) casts on _o_ and _n_ move off the call and into _old_ and _new_ declarations that type check the old and new arguments against *ptr through (unsigned long)(0 ? *ptr : (o)), the idiom David Laight suggested, so cmpxchg(&p, 4, 5) no longer compiles silently. Signed-off-by: Bradley Morgan Reviewed-by: David Laight Reviewed-by: Paul E. McKenney --- arch/xtensa/include/asm/cmpxchg.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cm= pxchg.h index b6db4838b175..f6bed4221b43 100644 --- a/arch/xtensa/include/asm/cmpxchg.h +++ b/arch/xtensa/include/asm/cmpxchg.h @@ -76,6 +76,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned= long new, int size) { switch (size) { case 1: return cmpxchg_emu_u8(ptr, old, new); + case 2: return cmpxchg_emu_u16(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); default: __cmpxchg_called_with_bad_pointer(); return old; @@ -83,10 +84,10 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsign= ed long new, int size) } =20 #define arch_cmpxchg(ptr,o,n) \ - ({ __typeof__(*(ptr)) _o_ =3D (o); \ - __typeof__(*(ptr)) _n_ =3D (n); \ - (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ - (unsigned long)_n_, sizeof (*(ptr))); \ + ({ unsigned long _old_ =3D (unsigned long)(0 ? *(ptr) : (o)); \ + unsigned long _new_ =3D (unsigned long)(0 ? *(ptr) : (n)); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), _old_, \ + _new_, sizeof (*(ptr))); \ }) =20 #include --=20 2.47.3