Skip to contentSkip to conversation

address violations of MISRA C:2012 Rule 10.1

PATCH Superseded Nicola Vetrini 3 participants 7 messages Nov 23, 2023 – Nov 29, 2023

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover address violations of MISRA C:2012 Rule 10.1

This series contains the leftover patches from [1] with the rename s/ISOLATE_LOW_BIT/ISOLATE_LSB/ applied. All the already committed patches from the aforementioned series are dropped.

[1] https://marc.info/?l=xen-devel&m=169841347803987

Nicola Vetrini (3):
arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 xen/pdx: amend definition of PDX_GROUP_COUNT x86_64/mm: express macro CNT using ISOLATE_LSB

 xen/arch/arm/include/asm/bitops.h |  4 ++--
 xen/arch/x86/x86_64/mm.c          | 12 ++++++------
 xen/include/xen/pdx.h             |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/3 arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1

The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the ISOLATE_LSB macro.

No functional change.

---
Changes in v4:
- Changed macro name.
Changes in v5:
- Changed macro name.

---
 xen/arch/arm/include/asm/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/include/asm/bitops.h +2 -2
index 71ae14cab355..673a8abae5bf 100644
@@ -155,8 +155,8 @@ static inline int fls(unsigned int x)
 }
 
 
-#define ffs(x) ({ unsigned int __t = (x); fls(__t & -__t); })
-#define ffsl(x) ({ unsigned long __t = (x); flsl(__t & -__t); })
+#define ffs(x) ({ unsigned int __t = (x); fls(ISOLATE_LSB(__t)); })
+#define ffsl(x) ({ unsigned long __t = (x); flsl(ISOLATE_LSB(__t)); })
 
 /**
  * find_first_set_bit - find the first set bit in @word
Signature · 1 line
2.34.1
#2 lore raw

Re: [XEN PATCH v5 1/3] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1

Quoted 7 lines · Nicola Vetrini

The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the ISOLATE_LSB macro.

No functional change.

This patch failed my pre-push build test; apparently xen/macros.h needs including explicitly.

Jan

#3 lore raw

Re: [XEN PATCH v5 1/3] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1

Quoted 6 lines · Jan Beulich
Quoted 5 lines · Nicola Vetrini

The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the ISOLATE_LSB macro.

No functional change.

Quoted 7 lines
Quoted 2 lines

This patch failed my pre-push build test; apparently xen/macros.h needs including explicitly.

Jan

Yes, indeed. I must have dropped that change when experimenting with single evaluation and then never reinstated it.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#4 lore raw

Re: [XEN PATCH v5 1/3] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1

Quoted 10 lines · Nicola Vetrini
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini

The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the ISOLATE_LSB macro.

No functional change.

Quoted 7 lines
Quoted 4 lines

This patch failed my pre-push build test; apparently xen/macros.h needs including explicitly.

Jan

Yes, indeed. I must have dropped that change when experimenting with single evaluation and then never reinstated it.

Please re-send

#5 lore raw

PATCH v5 2/3 xen/pdx: amend definition of PDX_GROUP_COUNT

In reply to Nicola Vetrini

The definition of PDX_GROUP_COUNT causes violations of MISRA C:2012 Rule 10.1, therefore the problematic part now uses the ISOLATE_LSB macro, which encapsulates the pattern.

---
Changes in v4:
- Changed macro name.
Changes in v5:
- Changed macro name.

---
 xen/include/xen/pdx.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/pdx.h +1 -1
index bd535009ea8f..23f3956db8db 100644
@@ -70,7 +70,7 @@
 extern unsigned long max_pdx;
 
 #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \
-                         (sizeof(*frame_table) & -sizeof(*frame_table)))
+                         (ISOLATE_LSB(sizeof(*frame_table))))
 extern unsigned long pdx_group_valid[];
 
 /**
Signature · 1 line
2.34.1
#6 lore raw

PATCH v5 3/3 x86_64/mm: express macro CNT using ISOLATE_LSB

In reply to Nicola Vetrini

The various definitions of macro CNT (and the related BUILD_BUG_ON) can be rewritten using ISOLATE_LSB, encapsulating a violation of MISRA C:2012 Rule 10.1.

---
Changes in v4:
- Changed macro name
Changes in v5:
- Add A-by
- Changed macro name.

---
 xen/arch/x86/x86_64/mm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/x86_64/mm.c +6 -6
index c3ebb777144a..b2a280fba369 100644
@@ -351,9 +351,9 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info)
                 ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );
 
 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int))
-#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \
+#define CNT (ISOLATE_LSB(sizeof(*frame_table)) / \
              sizeof(*compat_machine_to_phys_mapping))
-    BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \
+    BUILD_BUG_ON(ISOLATE_LSB(sizeof(*frame_table)) % \
                  sizeof(*compat_machine_to_phys_mapping));
 
     for ( i = smap; i < emap; i += (1UL << (L2_PAGETABLE_SHIFT - 2)) )
@@ -410,10 +410,10 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
     va = RO_MPT_VIRT_START + smap * sizeof(*machine_to_phys_mapping);
 
 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long))
-#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \
+#define CNT (ISOLATE_LSB(sizeof(*frame_table)) / \
              sizeof(*machine_to_phys_mapping))
 
-    BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \
+    BUILD_BUG_ON(ISOLATE_LSB(sizeof(*frame_table)) % \
                  sizeof(*machine_to_phys_mapping));
 
     i = smap;
@@ -539,7 +539,7 @@ void __init paging_init(void)
     mpt_size  = (max_page * BYTES_PER_LONG) + (1UL << L2_PAGETABLE_SHIFT) - 1;
     mpt_size &= ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);
 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long))
-#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \
+#define CNT (ISOLATE_LSB(sizeof(*frame_table)) / \
              sizeof(*machine_to_phys_mapping))
     BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \
                  sizeof(*machine_to_phys_mapping));
@@ -666,7 +666,7 @@ void __init paging_init(void)
         mpt_size = 0;
 
 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int))
-#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \
+#define CNT (ISOLATE_LSB(sizeof(*frame_table)) / \
              sizeof(*compat_machine_to_phys_mapping))
     BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \
                  sizeof(*compat_machine_to_phys_mapping));
Signature · 1 line
2.34.1