linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] compiler-gcc: hide COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW from sparse
@ 2018-11-09  9:34 Johannes Berg
  2018-11-09  9:34 ` [PATCH 2/3] kernel.h: hide __is_constexpr() " Johannes Berg
  2018-11-09  9:34 ` [PATCH 3/3] slab: use logical instead of bitwise operation in kmalloc_type() Johannes Berg
  0 siblings, 2 replies; 3+ messages in thread
From: Johannes Berg @ 2018-11-09  9:34 UTC (permalink / raw)
  To: linux-kernel, akmp; +Cc: Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

Sparse doesn't support all the overflow builtins, so just hide
them from it to avoid lots of warnings/errors reported by it.

We could try to teach them to sparse, but the passed types are
variable, and sparse doesn't seem to handle that well.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 2010493e1040..3154f2a84571 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -143,7 +143,7 @@
 #define KASAN_ABI_VERSION 3
 #endif
 
-#if GCC_VERSION >= 50100
+#if GCC_VERSION >= 50100 && !defined(__CHECKER__)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
 
-- 
2.17.2


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

* [PATCH 2/3] kernel.h: hide __is_constexpr() from sparse
  2018-11-09  9:34 [PATCH 1/3] compiler-gcc: hide COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW from sparse Johannes Berg
@ 2018-11-09  9:34 ` Johannes Berg
  2018-11-09  9:34 ` [PATCH 3/3] slab: use logical instead of bitwise operation in kmalloc_type() Johannes Berg
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Berg @ 2018-11-09  9:34 UTC (permalink / raw)
  To: linux-kernel, akmp; +Cc: Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

__is_constexpr() is a work of art, understandable only to the most
respected wizards of C. Even sparse doesn't seem to belong to that
group and warns that there's an "expression using sizeof(void)".

Just hide the definition from sparse and pretend it's always true.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/kernel.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d6aac75b51ba..d4d2233f95c9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -844,6 +844,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 #define __typecheck(x, y) \
 		(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 
+#ifndef __CHECKER__
 /*
  * This returns a constant expression while determining if an argument is
  * a constant expression, most importantly without evaluating the argument.
@@ -851,6 +852,13 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  */
 #define __is_constexpr(x) \
 	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+#else
+/*
+ * We don't really care about the check when running sparse and the
+ * above expression causes a warning due to sizeof(void).
+ */
+#define __is_constexpr(x) 1
+#endif
 
 #define __no_side_effects(x, y) \
 		(__is_constexpr(x) && __is_constexpr(y))
-- 
2.17.2


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

* [PATCH 3/3] slab: use logical instead of bitwise operation in kmalloc_type()
  2018-11-09  9:34 [PATCH 1/3] compiler-gcc: hide COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW from sparse Johannes Berg
  2018-11-09  9:34 ` [PATCH 2/3] kernel.h: hide __is_constexpr() " Johannes Berg
@ 2018-11-09  9:34 ` Johannes Berg
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Berg @ 2018-11-09  9:34 UTC (permalink / raw)
  To: linux-kernel, akmp; +Cc: Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

The operation here really is more logical than bitwise, even if
due to the setup the bitwise operation works fine. However, this
causes a complaint from sparse that the operation doesn't really
make sense due to the not.

Use a logical and instead of bitwise.

In my (somewhat unscientific) test this caused no differences in
the generated code.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 918f374e7156..d395c7366312 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -329,7 +329,7 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
 	 * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return
 	 * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE
 	 */
-	return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM;
+	return type_dma + (is_reclaimable && !is_dma) * KMALLOC_RECLAIM;
 }
 
 /*
-- 
2.17.2


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

end of thread, other threads:[~2018-11-09  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09  9:34 [PATCH 1/3] compiler-gcc: hide COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW from sparse Johannes Berg
2018-11-09  9:34 ` [PATCH 2/3] kernel.h: hide __is_constexpr() " Johannes Berg
2018-11-09  9:34 ` [PATCH 3/3] slab: use logical instead of bitwise operation in kmalloc_type() Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).