diff options
author | Johannes Berg <johannes.berg@intel.com> | 2016-08-26 02:16:00 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-09-05 05:50:42 -0400 |
commit | d7127b5e5fa0551be21b86640f1648b224e36d43 (patch) | |
tree | dd35da3a05da721d36c353ddea11555d4eb14362 /include/linux/compiler.h | |
parent | c6935931c1894ff857616ff8549b61236a19148f (diff) |
locking/barriers: Don't use sizeof(void) in lockless_dereference()
My previous commit:
112dc0c8069e ("locking/barriers: Suppress sparse warnings in lockless_dereference()")
caused sparse to complain that (in radix-tree.h) we use sizeof(void)
since that rcu_dereference()s a void *.
Really, all we need is to have the expression *p in here somewhere
to make sure p is a pointer type, and sizeof(*p) was the thing that
came to my mind first to make sure that's done without really doing
anything at runtime.
Another thing I had considered was using typeof(*p), but obviously
we can't just declare a typeof(*p) variable either, since that may
end up being void. Declaring a variable as typeof(*p)* gets around
that, and still checks that typeof(*p) is valid, so do that. This
type construction can't be done for _________p1 because that will
actually be used and causes sparse address space warnings, so keep
a separate unused variable for it.
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E . McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kbuild-all@01.org
Fixes: 112dc0c8069e ("locking/barriers: Suppress sparse warnings in lockless_dereference()")
Link: http://lkml.kernel.org/r/1472192160-4049-1-git-send-email-johannes@sipsolutions.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r-- | include/linux/compiler.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 436aa4e42221..668569844d37 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
@@ -527,13 +527,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | |||
527 | * object's lifetime is managed by something other than RCU. That | 527 | * object's lifetime is managed by something other than RCU. That |
528 | * "something other" might be reference counting or simple immortality. | 528 | * "something other" might be reference counting or simple immortality. |
529 | * | 529 | * |
530 | * The seemingly unused size_t variable is to validate @p is indeed a pointer | 530 | * The seemingly unused variable ___typecheck_p validates that @p is |
531 | * type by making sure it can be dereferenced. | 531 | * indeed a pointer type by using a pointer to typeof(*p) as the type. |
532 | * Taking a pointer to typeof(*p) again is needed in case p is void *. | ||
532 | */ | 533 | */ |
533 | #define lockless_dereference(p) \ | 534 | #define lockless_dereference(p) \ |
534 | ({ \ | 535 | ({ \ |
535 | typeof(p) _________p1 = READ_ONCE(p); \ | 536 | typeof(p) _________p1 = READ_ONCE(p); \ |
536 | size_t __maybe_unused __size_of_ptr = sizeof(*(p)); \ | 537 | typeof(*(p)) *___typecheck_p __maybe_unused; \ |
537 | smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ | 538 | smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ |
538 | (_________p1); \ | 539 | (_________p1); \ |
539 | }) | 540 | }) |