Skip to content

Commit b16d8ec

Browse files
committed
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 <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 8d4beed commit b16d8ec

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/linux/compiler.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,12 @@ unsigned long __read_once_word_nocheck(const void *addr)
254254
*/
255255
#define READ_ONCE_NOCHECK(x) \
256256
({ \
257-
unsigned long __x = __read_once_word_nocheck(&(x)); \
257+
unsigned long __x; \
258+
compiletime_assert(sizeof(x) == sizeof(__x), \
259+
"Unsupported access size for READ_ONCE_NOCHECK()."); \
260+
__x = __read_once_word_nocheck(&(x)); \
258261
smp_read_barrier_depends(); \
259-
__x; \
262+
(typeof(x))__x; \
260263
})
261264

262265
static __no_kasan_or_inline

0 commit comments

Comments
 (0)