summaryrefslogtreecommitdiff
path: root/include/linux/compiler.h
diff options
context:
space:
mode:
authorWill Deacon <will@kernel.org>2020-06-05 11:19:46 +0100
committerWill Deacon <will@kernel.org>2020-06-05 11:19:46 +0100
commitb16d8ecf4fa17e16fff20638364f9bd2205615e7 (patch)
treefae3ab27bddd1aab6d902dfd705caa322db7161f /include/linux/compiler.h
parent8d4beed7bbc71666de2630b79899c8852c3bf5cd (diff)
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>
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r--include/linux/compiler.h7
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