[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xen/x86: atomic: Don't allow to write atomically in a pointer to const



commit a82582b1af6a4a57ca53bcfad9f71428cb5f9a54
Author:     Julien Grall <jgrall@xxxxxxxxxx>
AuthorDate: Sat May 2 15:26:10 2020 +0100
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Mon May 11 10:50:17 2020 +0100

    xen/x86: atomic: Don't allow to write atomically in a pointer to const
    
    At the moment, write_atomic() will happily write to a pointer to const.
    While there are no use in Xen, it would be best to catch them at
    compilation time.
    
    Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/include/asm-x86/atomic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index 6b40f9c9f8..27aad43aaa 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -63,6 +63,8 @@ void __bad_atomic_size(void);
 
 #define write_atomic(p, x) ({                             \
     typeof(*(p)) __x = (x);                               \
+    /* Check that the pointer is not a const type */      \
+    void *__maybe_unused p_ = &__x;                       \
     unsigned long x_ = (unsigned long)__x;                \
     switch ( sizeof(*(p)) ) {                             \
     case 1: write_u8_atomic((uint8_t *)(p), x_); break;   \
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.