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

Xenia Ragiadakou posted 1 patch 1 year, 8 months ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20220805084354.1847282-1-burzalodowa@gmail.com
xen/common/cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] xen/cpu: Fix MISRA C 2012 Rule 20.7 violation
Posted by Xenia Ragiadakou 1 year, 8 months ago
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.

Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
---
 xen/common/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index b0b63cdb36..31fb5be5d9 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -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)
-- 
2.34.1
Re: [PATCH] xen/cpu: Fix MISRA C 2012 Rule 20.7 violation
Posted by Jan Beulich 1 year, 8 months ago
On 05.08.2022 10:43, Xenia Ragiadakou wrote:
> --- a/xen/common/cpu.c
> +++ b/xen/common/cpu.c
> @@ -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 ...

>  #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