Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: Silence sparse warnings caused by the type casting in (cmp)xchg

The arm64 xchg/cmpxchg() wrappers cast the arguments to (unsigned long)
prior to invoking the static inline functions implementing the
operation. Some restrictive type annotations (e.g. __bitwise) lead to
sparse warnings like below:

sparse warnings: (new ones prefixed by >>)
fs/crypto/bio.c:67:17: sparse: sparse: cast from restricted blk_status_t
>> fs/crypto/bio.c:67:17: sparse: sparse: cast to restricted blk_status_t

Force the casting in the arm64 xchg/cmpxchg() wrappers to silence
sparse.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202602230947.uNRsPyBn-lkp@intel.com/
Link: https://lore.kernel.org/r/202602230947.uNRsPyBn-lkp@intel.com/
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Catalin Marinas and committed by
Will Deacon
212dd847 df6e4ab6

+7 -5
+7 -5
arch/arm64/include/asm/cmpxchg.h
··· 91 91 #define __xchg_wrapper(sfx, ptr, x) \ 92 92 ({ \ 93 93 __typeof__(*(ptr)) __ret; \ 94 - __ret = (__typeof__(*(ptr))) \ 95 - __arch_xchg##sfx((unsigned long)(x), (ptr), sizeof(*(ptr))); \ 94 + __ret = (__force __typeof__(*(ptr))) \ 95 + __arch_xchg##sfx((__force unsigned long)(x), (ptr), \ 96 + sizeof(*(ptr))); \ 96 97 __ret; \ 97 98 }) 98 99 ··· 176 175 #define __cmpxchg_wrapper(sfx, ptr, o, n) \ 177 176 ({ \ 178 177 __typeof__(*(ptr)) __ret; \ 179 - __ret = (__typeof__(*(ptr))) \ 180 - __cmpxchg##sfx((ptr), (unsigned long)(o), \ 181 - (unsigned long)(n), sizeof(*(ptr))); \ 178 + __ret = (__force __typeof__(*(ptr))) \ 179 + __cmpxchg##sfx((ptr), (__force unsigned long)(o), \ 180 + (__force unsigned long)(n), \ 181 + sizeof(*(ptr))); \ 182 182 __ret; \ 183 183 }) 184 184