Skip to content

Commit 331b6d8

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
locking/barriers: Validate lockless_dereference() is used on a pointer type
Use the type to validate the argument @p is indeed a pointer type. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20160522104827.GP3193@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a461d58 commit 331b6d8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/linux/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
545545
* Similar to rcu_dereference(), but for situations where the pointed-to
546546
* object's lifetime is managed by something other than RCU. That
547547
* "something other" might be reference counting or simple immortality.
548+
*
549+
* The seemingly unused void * variable is to validate @p is indeed a pointer
550+
* type. All pointer types silently cast to void *.
548551
*/
549552
#define lockless_dereference(p) \
550553
({ \
551554
typeof(p) _________p1 = READ_ONCE(p); \
555+
__maybe_unused const void * const _________p2 = _________p1; \
552556
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
553557
(_________p1); \
554558
})

0 commit comments

Comments
 (0)