public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg
@ 2026-02-27 15:51 Catalin Marinas
  2026-03-03 15:21 ` Christoph Hellwig
  2026-03-04 16:59 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Catalin Marinas @ 2026-02-27 15:51 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: kernel test robot, Will Deacon, Mark Rutland, Christoph Hellwig

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>
---
 arch/arm64/include/asm/cmpxchg.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/include/asm/cmpxchg.h b/arch/arm64/include/asm/cmpxchg.h
index d7a540736741..6cf3cd6873f5 100644
--- a/arch/arm64/include/asm/cmpxchg.h
+++ b/arch/arm64/include/asm/cmpxchg.h
@@ -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;								\
 })
 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg
  2026-02-27 15:51 [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg Catalin Marinas
@ 2026-03-03 15:21 ` Christoph Hellwig
  2026-03-04 16:59 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-03-03 15:21 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: linux-arm-kernel, kernel test robot, Will Deacon, Mark Rutland,
	Christoph Hellwig

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg
  2026-02-27 15:51 [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg Catalin Marinas
  2026-03-03 15:21 ` Christoph Hellwig
@ 2026-03-04 16:59 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2026-03-04 16:59 UTC (permalink / raw)
  To: linux-arm-kernel, Catalin Marinas
  Cc: kernel-team, Will Deacon, kernel test robot, Mark Rutland,
	Christoph Hellwig

On Fri, 27 Feb 2026 15:51:42 +0000, Catalin Marinas wrote:
> 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
> 
> [...]

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,
-- 
Will

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-04 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 15:51 [PATCH] arm64: Silence sparse warnings caused by the type casting in (cmp)xchg Catalin Marinas
2026-03-03 15:21 ` Christoph Hellwig
2026-03-04 16:59 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox