Skip to contentSkip to conversation

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

PATCH Applied Catalin Marinas 3 participants 3 messages Feb 27 – Mar 4 arm64

lore
Share & tools
lore

Catalin Marinas

author maintainer
#0 lore raw

PATCH 1/1 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

Quoted 1 line
Quoted 1 line

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.

---
 arch/arm64/include/asm/cmpxchg.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
arch/arm64/include/asm/cmpxchg.h +7 -5
index d7a540736741..6cf3cd6873f5 100644
@@ -91,8 +91,9 @@ __XCHG_GEN(_mb)
 #define __xchg_wrapper(sfx, ptr, x)					\
 ({									\
 	__typeof__(*(ptr)) __ret;					\
-	__ret = (__typeof__(*(ptr)))					\
-		__arch_xchg##sfx((unsigned long)(x), (ptr), sizeof(*(ptr))); \
+	__ret = (__force __typeof__(*(ptr)))				\
+		__arch_xchg##sfx((__force unsigned long)(x), (ptr),	\
+				  sizeof(*(ptr)));			\
 	__ret;								\
 })
 
@@ -175,9 +176,10 @@ __CMPXCHG_GEN(_mb)
 #define __cmpxchg_wrapper(sfx, ptr, o, n)				\
 ({									\
 	__typeof__(*(ptr)) __ret;					\
-	__ret = (__typeof__(*(ptr)))					\
-		__cmpxchg##sfx((ptr), (unsigned long)(o),		\
-				(unsigned long)(n), sizeof(*(ptr)));	\
+	__ret = (__force __typeof__(*(ptr)))				\
+		__cmpxchg##sfx((ptr), (__force unsigned long)(o),	\
+				(__force unsigned long)(n),		\
+				sizeof(*(ptr)));			\
 	__ret;								\
 })
 
maintainer Applied
#2 lore raw
In reply to Catalin Marinas
Quoted 10 lines · Catalin Marinas

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

Quoted 1 line
Quoted 1 line

fs/crypto/bio.c:67:17: sparse: sparse: cast to restricted blk_status_t

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg

      https://git.kernel.org/arm64/c/212dd8477653

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev