Skip to contentSkip to conversation

kernel.h: Avoid that sparse complains about using sizeof(void)

PATCH In review Bart Van Assche 5 participants 8 messages Jul 5, 2018 – Jul 16, 2018 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.h: Avoid that sparse complains about using sizeof(void)

The macro __is_constexpr() causes sparse to report the following:

warning: expression using sizeof(void)

Avoid this by using __builtin_constant_p() instead.

Fixes 3c8ba0d61d04 ("kernel.h: Retain constant expression output for max()/min()")
Cc Linus Torvalds <[email protected]>
Cc Martin Uecker <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Miguel Ojeda <[email protected]>
---
 include/linux/kernel.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/kernel.h +7 -1
index d23123238534..a9f0d0d48971 100644
@@ -811,13 +811,19 @@ 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.
- * Glory to Martin Uecker <[email protected]>
+ * Glory to Martin Uecker <[email protected]>. However, this
+ * macro causes sparse to report the warning "expression using sizeof(void)".
+ * Hence use __builtin_constant_p() instead when using sparse.
  */
 #define __is_constexpr(x) \
 	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+#else
+#define __is_constexpr(x) __builtin_constant_p((x))
+#endif
 
 #define __no_side_effects(x, y) \
 		(__is_constexpr(x) && __is_constexpr(y))
Signature · 1 line
2.18.0
Acked-by on v1 1/1
#1 lore raw
Quoted 33 lines · Bart Van Assche

The macro __is_constexpr() causes sparse to report the following:

warning: expression using sizeof(void)

Avoid this by using __builtin_constant_p() instead.

Fixes 3c8ba0d61d04 ("kernel.h: Retain constant expression output for max()/min()")
Cc Linus Torvalds <[email protected]>
Cc Martin Uecker <[email protected]>
Cc Kees Cook <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Miguel Ojeda <[email protected]>
---
 include/linux/kernel.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/kernel.h +3 -1
index d23123238534..a9f0d0d48971 100644
@@ -811,13 +811,19 @@ 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.
- * Glory to Martin Uecker <[email protected]>
+ * Glory to Martin Uecker <[email protected]>. However, this
+ * macro causes sparse to report the warning "expression using sizeof(void)".

include/linux/kernel.h static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } · line 829

Quoted 10 lines
include/linux/kernel.h +4 -0
+ * Hence use __builtin_constant_p() instead when using sparse.
  */
 #define __is_constexpr(x) \
        (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+#else
+#define __is_constexpr(x) __builtin_constant_p((x))
+#endif
 
 #define __no_side_effects(x, y) \
                (__is_constexpr(x) && __is_constexpr(y))

I'm fine with this; it'll only activate for sparse. I'd like to get Linus's eyes on it, though, since this macro caused us SO much pain that I'm nervous to change it without some greater level of review. :)

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
Quoted 4 lines · Kees Cook

I'm fine with this; it'll only activate for sparse. I'd like to get Linus's eyes on it, though, since this macro caused us SO much pain that I'm nervous to change it without some greater level of review. :)

Honestly, I'd like to just encourage people to get the sparse update from Luc Van Oostenryck instead.

For a while there it looked like Chris Li would just pull from Luc, and we'd have timely releases, but that really doesn't seem to have ended up happening after all. So right now it's probably just best to get Luc's tree instead from

https://github.com/lucvoo/sparse-dev

which also ends up fixing a lot of other issues.

Linus

#3 lore raw

Oh,
and I meant to cc Luc on that email, but then forgot. So here he is cc'd now.

Linus

Quoted 14 lines · Linus Torvalds

Honestly, I'd like to just encourage people to get the sparse update from Luc Van Oostenryck instead.

For a while there it looked like Chris Li would just pull from Luc, and we'd have timely releases, but that really doesn't seem to have ended up happening after all. So right now it's probably just best to get Luc's tree instead from

https://github.com/lucvoo/sparse-dev

which also ends up fixing a lot of other issues.

Linus

#4 lore raw
Quoted 13 lines · Linus Torvalds
Quoted 11 lines · Linus Torvalds

Honestly, I'd like to just encourage people to get the sparse update from Luc Van Oostenryck instead.

For a while there it looked like Chris Li would just pull from Luc, and we'd have timely releases, but that really doesn't seem to have ended up happening after all. So right now it's probably just best to get Luc's tree instead from

https://github.com/lucvoo/sparse-dev

Quoted 8 lines
Quoted 3 lines

which also ends up fixing a lot of other issues.

Linus

Oh,
and I meant to cc Luc on that email, but then forgot. So here he is cc'd now.

Linus

Hello everyone,

I will switch to Luc's sparse tree.

Thank you for the feedback.

Bart.

#5 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 8 lines · Linus Torvalds

Honestly, I'd like to just encourage people to get the sparse update from Luc Van Oostenryck instead.

For a while there it looked like Chris Li would just pull from Luc, and we'd have timely releases, but that really doesn't seem to have ended up happening after all. So right now it's probably just best to get Luc's tree instead from

Quoted 6 lines
Quoted 3 lines

https://github.com/lucvoo/sparse-dev

which also ends up fixing a lot of other issues.

Oh,
and I meant to cc Luc on that email, but then forgot. So here he is cc'd now.

(+- Konstantin)

Something that is confusing for kernel developers is that the sparse wiki
(https://sparse.wiki.kernel.org/index.php/Main_Page) refers kernel developers to an outdated sparse tree. Should something be done about this inconsistency? Should the sparse wiki point at one of Luc's sparse trees or should perhaps Luc be granted access to the tree that wiki points at
(https://git.kernel.org/pub/scm/devel/sparse/sparse.git)?

Thanks,

Bart.

#6 lore raw
Quoted 11 lines · Bart Van Assche
Quoted 2 lines

Oh,
and I meant to cc Luc on that email, but then forgot. So here he is cc'd now.

(+ Konstantin)

Something that is confusing for kernel developers is that the sparse wiki
(https://sparse.wiki.kernel.org/index.php/Main_Page) refers kernel developers to an outdated sparse tree. Should something be done about this inconsistency? Should the sparse wiki point at one of Luc's sparse trees or should perhaps Luc be granted access to the tree that wiki points at
(https://git.kernel.org/pub/scm/devel/sparse/sparse.git)?

I believe Luc is working to get the necessary signatures on his PGP key so we can grant him access to the repo at kernel.org. I believe this will be less confusing than modifying the wiki to point to the github fork of the tree.

Best,
Konstantin

#7 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 4 lines · Kees Cook

I'm fine with this; it'll only activate for sparse. I'd like to get Linus's eyes on it, though, since this macro caused us SO much pain that I'm nervous to change it without some greater level of review. :)

Honestly, I'd like to just encourage people to get the sparse update from Luc Van Oostenryck instead.

Quoted 8 lines

For a while there it looked like Chris Li would just pull from Luc, and we'd have timely releases, but that really doesn't seem to have ended up happening after all. So right now it's probably just best to get Luc's tree instead from

https://github.com/lucvoo/sparse-dev

which also ends up fixing a lot of other issues.

Thank you.

I'll try to move my trees to kernel.org in the coming days or weeks, it will be better for everyone, I think (I just need one more signature on my gpg key).

Meanwhile, I prefer that people use my 'stable' tree:
https://github.com/lucvoo/sparse
(never rebased, only contains the master branch and one backport) while my sparse-dev repository is mainly a bunch of topic branches in diverse state of development (but the master branch is the same so it doesn't matter much).

-- Luc