Skip to content

Commit ba33034

Browse files
borntraegerIngo Molnar
authored andcommitted
locking, compiler.h: Cast away attributes in the WRITE_ONCE() magic
The kernel build bot showed a new warning triggered by commit: 76695af ("locking, arch: use WRITE_ONCE()/READ_ONCE() in smp_store_release()/smp_load_acquire()") because Sparse does not like WRITE_ONCE() accessing elements from the (sparse) RCU address space: fs/afs/inode.c:448:9: sparse: incorrect type in initializer (different address spaces) fs/afs/inode.c:448:9: expected struct afs_permits *__val fs/afs/inode.c:448:9: got void [noderef] <asn:4>*<noident> Solution is to force cast away the sparse attributes for the initializer of the union in WRITE_ONCE(). (And as this now gets too long, also split the macro into multiple lines.) Signed-off-by: Christian Borntraeger <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent f52609f commit ba33034

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/linux/compiler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
252252
({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
253253

254254
#define WRITE_ONCE(x, val) \
255-
({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
255+
({ \
256+
union { typeof(x) __val; char __c[1]; } __u = \
257+
{ .__val = (__force typeof(x)) (val) }; \
258+
__write_once_size(&(x), __u.__c, sizeof(x)); \
259+
__u.__val; \
260+
})
256261

257262
/**
258263
* READ_ONCE_CTRL - Read a value heading a control dependency

0 commit comments

Comments
 (0)