Skip to content

Commit 3364c6c

Browse files
keesctmarinas
authored andcommitted
arm64: atomics: lse: Dereference matching size
When building with -Warray-bounds, the following warning is generated: In file included from ./arch/arm64/include/asm/lse.h:16, from ./arch/arm64/include/asm/cmpxchg.h:14, from ./arch/arm64/include/asm/atomic.h:16, from ./include/linux/atomic.h:7, from ./include/asm-generic/bitops/atomic.h:5, from ./arch/arm64/include/asm/bitops.h:25, from ./include/linux/bitops.h:33, from ./include/linux/kernel.h:22, from kernel/printk/printk.c:22: ./arch/arm64/include/asm/atomic_lse.h:247:9: warning: array subscript 'long unsigned int[0]' is partly outside array bounds of 'atomic_t[1]' [-Warray-bounds] 247 | asm volatile( \ | ^~~ ./arch/arm64/include/asm/atomic_lse.h:266:1: note: in expansion of macro '__CMPXCHG_CASE' 266 | __CMPXCHG_CASE(w, , acq_, 32, a, "memory") | ^~~~~~~~~~~~~~ kernel/printk/printk.c:3606:17: note: while referencing 'printk_cpulock_owner' 3606 | static atomic_t printk_cpulock_owner = ATOMIC_INIT(-1); | ^~~~~~~~~~~~~~~~~~~~ This is due to the compiler seeing an unsigned long * cast against something (atomic_t) that is int sized. Replace the cast with the matching size cast. This results in no change in binary output. Note that __ll_sc__cmpxchg_case_##name##sz already uses the same constraint: [v] "+Q" (*(u##sz *)ptr Which is why only the LSE form needs updating and not the LL/SC form, so this change is unlikely to be problematic. Cc: Will Deacon <will@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: linux-arm-kernel@lists.infradead.org Acked-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220112202259.3950286-1-keescook@chromium.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 440323b commit 3364c6c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

arch/arm64/include/asm/atomic_lse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ __lse__cmpxchg_case_##name##sz(volatile void *ptr, \
249249
" mov %" #w "[tmp], %" #w "[old]\n" \
250250
" cas" #mb #sfx "\t%" #w "[tmp], %" #w "[new], %[v]\n" \
251251
" mov %" #w "[ret], %" #w "[tmp]" \
252-
: [ret] "+r" (x0), [v] "+Q" (*(unsigned long *)ptr), \
252+
: [ret] "+r" (x0), [v] "+Q" (*(u##sz *)ptr), \
253253
[tmp] "=&r" (tmp) \
254254
: [old] "r" (x1), [new] "r" (x2) \
255255
: cl); \

arch/arm64/include/asm/cmpxchg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static inline void __cmpwait_case_##sz(volatile void *ptr, \
243243
" cbnz %" #w "[tmp], 1f\n" \
244244
" wfe\n" \
245245
"1:" \
246-
: [tmp] "=&r" (tmp), [v] "+Q" (*(unsigned long *)ptr) \
246+
: [tmp] "=&r" (tmp), [v] "+Q" (*(u##sz *)ptr) \
247247
: [val] "r" (val)); \
248248
}
249249

0 commit comments

Comments
 (0)