Skip to contentSkip to conversation

byteswap: don't use __builtin_bswap*() with sparse

PATCH Applied Johannes Berg 2 participants 2 messages Aug 11, 2016 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 byteswap: don't use __builtin_bswap*() with sparse

From: Johannes Berg <[email protected]>

Although sparse declares __builtin_bswap*(), it can't actually do constant folding inside them (yet). As such, things like

  switch (protocol) {
  case htons(ETH_P_IP):
          break;
  }

which we do all over the place cause sparse to warn that it expects a constant instead of a function call.

Disable __HAVE_BUILTIN_BSWAP*__ if __CHECKER__ is defined to avoid this.

Cc Arnd Bergmann <[email protected]>
Fixes 7322dd755e7d ("byteswap: try to avoid __builtin_constant_p gcc bug")
---
 include/linux/compiler-gcc.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
include/linux/compiler-gcc.h +6 -2
index e2949397c19b..8dbc8929a6a0 100644
@@ -242,7 +242,11 @@
  */
 #define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
 
-#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
+/*
+ * sparse (__CHECKER__) pretends to be gcc, but can't do constant
+ * folding in __builtin_bswap*() (yet), so don't set these for it.
+ */
+#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__)
 #if GCC_VERSION >= 40400
 #define __HAVE_BUILTIN_BSWAP32__
 #define __HAVE_BUILTIN_BSWAP64__
@@ -250,7 +254,7 @@
 #if GCC_VERSION >= 40800
 #define __HAVE_BUILTIN_BSWAP16__
 #endif
-#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
+#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */
 
 #if GCC_VERSION >= 50000
 #define KASAN_ABI_VERSION 4
Signature · 1 line
2.8.1
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · CEST Johannes Berg

From: Johannes Berg <[email protected]>

Although sparse declares __builtin_bswap*(), it can't actually do constant folding inside them (yet). As such, things like

  switch (protocol) {
  case htons(ETH_P_IP):
          break;
  }

which we do all over the place cause sparse to warn that it expects a constant instead of a function call.

Quoted 6 lines

Disable __HAVE_BUILTIN_BSWAP*__ if __CHECKER__ is defined to avoid this.

Cc Arnd Bergmann <[email protected]>
Fixes 7322dd755e7d ("byteswap: try to avoid __builtin_constant_p gcc bug")

Looks good, thanks for addressing this!