Skip to contentSkip to conversation

xen/cpu: Fix MISRA C 2012 Rule 20.7 violation

PATCH Superseded Xenia Ragiadakou 2 participants 2 messages Aug 5, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/cpu: Fix MISRA C 2012 Rule 20.7 violation

In MASK_DECLARE_1(), the macro parameter 'x' is used as expression and therefore it is good to be enclosed in parentheses to prevent against unintended expansions.

---
 xen/common/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/cpu.c +1 -1
index b0b63cdb36..31fb5be5d9 100644
@@ -25,7 +25,7 @@ const cpumask_t cpumask_all = {
  */
 
 /* cpu_bit_bitmap[0] is empty - so we can back into it */
-#define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x)
+#define MASK_DECLARE_1(x) [(x)+1][0] = 1UL << (x)
 #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
 #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
 #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
Signature · 1 line
2.34.1
#1 lore raw

xen/common/cpu.c const cpumask_t cpumask_all = { · line 28

Quoted 8 lines · Xenia Ragiadakou
xen/common/cpu.c +1 -1
@@ -25,7 +25,7 @@ const cpumask_t cpumask_all = {
  */
 
 /* cpu_bit_bitmap[0] is empty - so we can back into it */
-#define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x)
+#define MASK_DECLARE_1(x) [(x)+1][0] = 1UL << (x)

If you adjust these, you also ...

xen/common/cpu.c const cpumask_t cpumask_all = { · line 31

Quoted 3 lines
xen/common/cpu.c +0 -0
 #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
 #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
 #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)

.. want to adjust all of these, as they all have a similar issue. And while doing such adjustments, please also add the missing blanks around + .

However, these are macros used locally in a single .c file only, so I'm not convinced as strict rules need to apply here. To make clear no further uses (farther apart from the macro definitions) are intended, an option would be to add #undef-s right after cpu_bit_bitmap[]'s initializer. (But this is not an objection to adding the parentheses, just a general remark.)

Jan