xen/cpu: Fix MISRA C 2012 Rule 20.7 violation
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
@@ -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
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