Commit 112dc0c8 authored by Johannes Berg's avatar Johannes Berg Committed by Ingo Molnar

locking/barriers: Suppress sparse warnings in lockless_dereference()

After Peter's commit:

  331b6d8c ("locking/barriers: Validate lockless_dereference() is used on a pointer type")

... we get a lot of sparse warnings (one for every rcu_dereference, and more)
since the expression here is assigning to the wrong address space.

Instead of validating that 'p' is a pointer this way, instead make
it fail compilation when it's not by using sizeof(*(p)). This will
not cause any sparse warnings (tested, likely since the address
space is irrelevant for sizeof), and will fail compilation when
'p' isn't a pointer type.
Tested-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 331b6d8c ("locking/barriers: Validate lockless_dereference() is used on a pointer type")
Link: http://lkml.kernel.org/r/1470909022-687-2-git-send-email-johannes@sipsolutions.netSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent f17b3ea3
...@@ -527,13 +527,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s ...@@ -527,13 +527,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
* object's lifetime is managed by something other than RCU. That * object's lifetime is managed by something other than RCU. That
* "something other" might be reference counting or simple immortality. * "something other" might be reference counting or simple immortality.
* *
* The seemingly unused void * variable is to validate @p is indeed a pointer * The seemingly unused size_t variable is to validate @p is indeed a pointer
* type. All pointer types silently cast to void *. * type by making sure it can be dereferenced.
*/ */
#define lockless_dereference(p) \ #define lockless_dereference(p) \
({ \ ({ \
typeof(p) _________p1 = READ_ONCE(p); \ typeof(p) _________p1 = READ_ONCE(p); \
__maybe_unused const void * const _________p2 = _________p1; \ size_t __maybe_unused __size_of_ptr = sizeof(*(p)); \
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
(_________p1); \ (_________p1); \
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment