Skip to contentSkip to conversation

x86/cpu-policy: Adjust CPUID_MAX_SERIALISED_LEAVES to placate MISRA

PATCH In review Andrew Cooper 3 participants 3 messages Oct 10, 2023 – Oct 16, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu-policy: Adjust CPUID_MAX_SERIALISED_LEAVES to placate MISRA

MISRA doesn't like !!CONST being used in place of a 1 (Rule 10.1). Update the expression to just be a plain 1, which still matches the description.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Nicola Vetrini <[email protected]>

After considering the comment several times, I've decided to leave it as is. It's slightly awkward grammar but it's ok.

---
 xen/include/xen/lib/x86/cpu-policy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
xen/include/xen/lib/x86/cpu-policy.h +8 -7
index bab3eecda6c1..d5e447e9dc06 100644
@@ -100,13 +100,14 @@ const char *x86_cpuid_vendor_to_str(unsigned int vendor);
  * interaction with the toolstack.  (Sum of all leaves in each union, less the
  * entries in basic which sub-unions hang off of.)
  */
-#define CPUID_MAX_SERIALISED_LEAVES                     \
-    (CPUID_GUEST_NR_BASIC +                             \
-     CPUID_GUEST_NR_FEAT   - !!CPUID_GUEST_NR_FEAT +    \
-     CPUID_GUEST_NR_CACHE  - !!CPUID_GUEST_NR_CACHE +   \
-     CPUID_GUEST_NR_TOPO   - !!CPUID_GUEST_NR_TOPO +    \
-     CPUID_GUEST_NR_XSTATE - !!CPUID_GUEST_NR_XSTATE +  \
-     CPUID_GUEST_NR_EXTD + 2 /* hv_limit and hv2_limit */ )
+#define CPUID_MAX_SERIALISED_LEAVES             \
+    (CPUID_GUEST_NR_BASIC +                     \
+     CPUID_GUEST_NR_FEAT   - 1 +                \
+     CPUID_GUEST_NR_CACHE  - 1 +                \
+     CPUID_GUEST_NR_TOPO   - 1 +                \
+     CPUID_GUEST_NR_XSTATE - 1 +                \
+     CPUID_GUEST_NR_EXTD +                      \
+     2 /* hv_limit and hv2_limit */ )
 
 /* Maximum number of MSRs written when serialising a cpu_policy. */
 #define MSR_MAX_SERIALISED_ENTRIES 2

base-commit: c035151902689aa5a3765aeb16fa52755917b9ca

Signature · 1 line
2.30.2
#1 lore raw
Quoted 49 lines · Andrew Cooper

MISRA doesn't like !!CONST being used in place of a 1 (Rule 10.1). Update the expression to just be a plain 1, which still matches the description.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Nicola Vetrini <[email protected]>

After considering the comment several times, I've decided to leave it as is. It's slightly awkward grammar but it's ok.

---
 xen/include/xen/lib/x86/cpu-policy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
xen/include/xen/lib/x86/cpu-policy.h +0 -0
index bab3eecda6c1..d5e447e9dc06 100644
@@ -100,13 +100,14 @@ const char *x86_cpuid_vendor_to_str(unsigned int 
 vendor);
  * interaction with the toolstack.  (Sum of all leaves in each union, 

less the
* entries in basic which sub-unions hang off of.) */

xen/include/xen/lib/x86/cpu-policy.h +8 -7
-#define CPUID_MAX_SERIALISED_LEAVES                     \
-    (CPUID_GUEST_NR_BASIC +                             \
-     CPUID_GUEST_NR_FEAT   - !!CPUID_GUEST_NR_FEAT +    \
-     CPUID_GUEST_NR_CACHE  - !!CPUID_GUEST_NR_CACHE +   \
-     CPUID_GUEST_NR_TOPO   - !!CPUID_GUEST_NR_TOPO +    \
-     CPUID_GUEST_NR_XSTATE - !!CPUID_GUEST_NR_XSTATE +  \
-     CPUID_GUEST_NR_EXTD + 2 /* hv_limit and hv2_limit */ )
+#define CPUID_MAX_SERIALISED_LEAVES             \
+    (CPUID_GUEST_NR_BASIC +                     \
+     CPUID_GUEST_NR_FEAT   - 1 +                \
+     CPUID_GUEST_NR_CACHE  - 1 +                \
+     CPUID_GUEST_NR_TOPO   - 1 +                \
+     CPUID_GUEST_NR_XSTATE - 1 +                \
+     CPUID_GUEST_NR_EXTD +                      \
+     2 /* hv_limit and hv2_limit */ )
 
 /* Maximum number of MSRs written when serialising a cpu_policy. */
 #define MSR_MAX_SERIALISED_ENTRIES 2
Quoted 1 line

base-commit: c035151902689aa5a3765aeb16fa52755917b9ca

Looks good to me.

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