diff options
author | Will Deacon <will@kernel.org> | 2020-06-05 12:19:46 +0200 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2020-06-05 12:19:46 +0200 |
commit | b16d8ecf4fa17e16fff20638364f9bd2205615e7 (patch) | |
tree | fae3ab27bddd1aab6d902dfd705caa322db7161f | |
parent | compiler-types.h: Include naked type in __pick_integer_type() match (diff) | |
download | linux-b16d8ecf4fa17e16fff20638364f9bd2205615e7.tar.xz linux-b16d8ecf4fa17e16fff20638364f9bd2205615e7.zip |
compiler.h: Enforce that READ_ONCE_NOCHECK() access size is sizeof(long)
READ_ONCE_NOCHECK() unconditionally performs a sizeof(long)-sized access,
so enforce that the size of the pointed-to object that we are loading
from is the same size as 'long'.
Reported-by: Marco Elver <elver@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | include/linux/compiler.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 657e4fd38a77..a0aa56e6b782 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -254,9 +254,12 @@ unsigned long __read_once_word_nocheck(const void *addr) */ #define READ_ONCE_NOCHECK(x) \ ({ \ - unsigned long __x = __read_once_word_nocheck(&(x)); \ + unsigned long __x; \ + compiletime_assert(sizeof(x) == sizeof(__x), \ + "Unsupported access size for READ_ONCE_NOCHECK()."); \ + __x = __read_once_word_nocheck(&(x)); \ smp_read_barrier_depends(); \ - __x; \ + (typeof(x))__x; \ }) static __no_kasan_or_inline |