| Message ID | 20260917163830.3748-6-brads@mainlining.org |
|---|---|
| State | New |
| Headers | show |
| Series | [v3,1/5] lib: Add two-byte cmpxchg emulation function | expand |
On 17 September 2026 17:38:30 BST, Bradley Morgan <brads@mainlining.org> wrote: >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_ at the call move into the function and the macro's >__typeof__(*(ptr)) typing of _o_ and _n_ remains the pointer-integer >type check. > >Signed-off-by: Bradley Morgan <brads@mainlining.org> >--- > arch/xtensa/include/asm/cmpxchg.h | 1 + > 1 file changed, 1 insertion(+) > >diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h >index b6db4838b175..8dea8e357fc0 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; > Oops! Forgot to add R-B tag! Merger, could you add this when it's ready to merge? --- Thanks! https://lore.kernel.org/all/EE579805-42F2-4C58-B752-F28779EEB717@grrlz.net/
diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h index b6db4838b175..8dea8e357fc0 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;
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_ at the call move into the function and the macro's __typeof__(*(ptr)) typing of _o_ and _n_ remains the pointer-integer type check. Signed-off-by: Bradley Morgan <brads@mainlining.org> --- arch/xtensa/include/asm/cmpxchg.h | 1 + 1 file changed, 1 insertion(+)