Skip to contentSkip to conversation

xen/arm: asm/atomic.h: Fix MISRA C 2012 Rule violations

PATCH Superseded Xenia Ragiadakou 2 participants 3 messages Jul 27, 2022 – Jul 28, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: asm/atomic.h: Fix MISRA C 2012 Rule violations

This patch series fixes violations of rule 20.7 found in xen/arch/arm/include/asm/atomic.h.

Changes in v2:
- removed redundant parentheses in patch 1/2
- dropped patch 2/2 that removes unused atomic_xchg() because changes Xen's atomic API, and such a change cannot be justified since compliance to MISRA C Rule 2.5 is advisory. If at some point it is decided to remove the relevant macro, this will be done for both arm and x86 with a separate patch.

Xenia Ragiadakou (1):
xen/arm: asm/atomic.h: Fix MISRA C 2012 Rule 20.7 violation

 xen/arch/arm/include/asm/atomic.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 xen/arm: asm/atomic.h: Fix MISRA C 2012 Rule 20.7 violation

The macro parameter 'p' is used as an expression and needs to be enclosed in parentheses.

---

Changes in v2:
- remove parentheses in the cases that p is not used as an expression that is when it is used as a function argument

 xen/arch/arm/include/asm/atomic.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/atomic.h +4 -4
index ac2798d095..1f60c28b1b 100644
@@ -123,15 +123,15 @@ static always_inline void write_atomic_size(volatile void *p,
 }
 
 #define read_atomic(p) ({                                               \
-    union { typeof(*p) val; char c[0]; } x_;                            \
-    read_atomic_size(p, x_.c, sizeof(*p));                              \
+    union { typeof(*(p)) val; char c[0]; } x_;                          \
+    read_atomic_size(p, x_.c, sizeof(*(p)));                            \
     x_.val;                                                             \
 })
 
 #define write_atomic(p, x)                                              \
     do {                                                                \
-        typeof(*p) x_ = (x);                                            \
-        write_atomic_size(p, &x_, sizeof(*p));                          \
+        typeof(*(p)) x_ = (x);                                          \
+        write_atomic_size(p, &x_, sizeof(*(p)));                        \
     } while ( false )
 
 #define add_sized(p, x) ({                                              \
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] xen/arm: asm/atomic.h: Fix MISRA C 2012 Rule 20.7 violation

Quoted 4 lines · Xenia Ragiadakou

The macro parameter 'p' is used as an expression and needs to be enclosed in parentheses.

Quoted 36 lines

---

Changes in v2:
- remove parentheses in the cases that p is not used as an expression that is when it is used as a function argument

 xen/arch/arm/include/asm/atomic.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/atomic.h +4 -4
index ac2798d095..1f60c28b1b 100644
@@ -123,15 +123,15 @@ static always_inline void write_atomic_size(volatile void *p,
 }
 
 #define read_atomic(p) ({                                               \
-    union { typeof(*p) val; char c[0]; } x_;                            \
-    read_atomic_size(p, x_.c, sizeof(*p));                              \
+    union { typeof(*(p)) val; char c[0]; } x_;                          \
+    read_atomic_size(p, x_.c, sizeof(*(p)));                            \
     x_.val;                                                             \
 })
 
 #define write_atomic(p, x)                                              \
     do {                                                                \
-        typeof(*p) x_ = (x);                                            \
-        write_atomic_size(p, &x_, sizeof(*p));                          \
+        typeof(*(p)) x_ = (x);                                          \
+        write_atomic_size(p, &x_, sizeof(*(p)));                        \
     } while ( false )
 
 #define add_sized(p, x) ({                                              \
Signature · 1 line
2.34.1