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.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -527,13 +527,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s · 526 unmodified lines | ||
| 527 | 527 | * object's lifetime is managed by something other than RCU. That |
| 528 | 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 | |
| 531 | − * type by making sure it can be dereferenced. | |
| 530 | + * The seemingly unused variable ___typecheck_p validates that @p is | |
| 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 | 534 | #define lockless_dereference(p) \ |
| 534 | 535 | ({ \ |
| 535 | 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 | 538 | smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ |
| 538 | 539 | (_________p1); \ |
| 539 | 540 | }) |