Re: [PATCH] cmpxchg: allow const-qualified old value in cmpxchg()

Hangbin Liu
2026-04-02T13:08:01Z

On Thu, Apr 02, 2026 at 09:57:47AM +0100, David Laight wrote:
> > diff --git a/arch/alpha/include/asm/cmpxchg.h b/arch/alpha/include/asm/cmpxchg.h
> > index ae1b96479d0c..b4b8dac759c4 100644
> > --- a/arch/alpha/include/asm/cmpxchg.h
> > +++ b/arch/alpha/include/asm/cmpxchg.h
> > @@ -234,7 +234,7 @@ ____cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
> >
> > #define arch_cmpxchg_local(ptr, o, n) \
> > ({ \
> > - __typeof__(*(ptr)) _o_ = (o); \
> > + __typeof__(*(ptr)) _o_ = (__typeof__(*(ptr)))(o); \
> > __typeof__(*(ptr)) _n_ = (n); \
> > (__typeof__(*(ptr))) ____cmpxchg((ptr), (unsigned long)_o_, \
> > (unsigned long)_n_, \
>
> That looks like it loses the check that 'o' has the same type as '*ptr'.
> Maybe this works?
> auto _o_ = 1 ? (o) : *(ptr);
>
Oh, I didn't notice this. Thanks for the comment!

Best Regards
Hangbin