x86/gen-cpuid: avoid violations of Misra rule 1.3
PATCH 1/1 x86/gen-cpuid: avoid violations of Misra rule 1.3
Structures or unions without any named members aren't liked by Misra (nor the C standard). Avoid emitting such for leaves without any known bits.
At this occasion also add the script to the X86 section in ./MAINTAINERS.
MAINTAINERS +1 -0
@@ -601,6 +601,7 @@ F: xen/arch/x86/ F: xen/include/public/arch-x86/ F: xen/include/xen/lib/x86 F: xen/lib/x86 +F: xen/tools/gen-cpuid.py F: tools/firmware/hvmloader/ F: tools/firmware/rombios/ F: tools/firmware/vgabios/
xen/tools/gen-cpuid.py +8 -1
@@ -367,6 +367,7 @@ def crunch_numbers(state): for word in range(state.nr_entries): names = [] + empty = 1 for bit in range(32): name = state.names.get(word * 32 + bit, "")
@@ -380,9 +381,15 @@ def crunch_numbers(state): if name in ("APIC", "OSXSAVE", "OSPKE"): name = "" + if name: + empty = 0 + names.append(name.lower()) - state.bitfields.append("bool " + ":1, ".join(names) + ":1") + if empty: + state.bitfields.append("unsigned int empty_" + str(word) + ":32") + else: + state.bitfields.append("bool " + ":1, ".join(names) + ":1") def write_results(state):
Quoted 32 lines · Jan Beulich
Structures or unions without any named members aren't liked by Misra (nor the C standard). Avoid emitting such for leaves without any known bits.
At this occasion also add the script to the X86 section in ./MAINTAINERS.
Signed-off-by Jan Beulich <[email protected]>MAINTAINERS +1
-0@@ -601,6 +601,7 @@ F: xen/arch/x86/ F: xen/include/public/arch-x86/ F: xen/include/xen/lib/x86 F: xen/lib/x86 +F: xen/tools/gen-cpuid.py F: tools/firmware/hvmloader/ F: tools/firmware/rombios/ F: tools/firmware/vgabios/xen/tools/gen-cpuid.py +1
-0@@ -367,6 +367,7 @@ def crunch_numbers(state): for word in range(state.nr_entries): names = [] + empty = 1 for bit in range(32): name = state.names.get(word * 32 + bit, "")@@ -380,9 +381,15 @@ def crunch_numbers(state): if name in ("APIC", "OSXSAVE", "OSPKE"): name = ""
xen/tools/gen-cpuid.py def crunch_numbers(state): · line 392
Quoted 10 lines
xen/tools/gen-cpuid.py +7
-1+ if name: + empty = 0 + names.append(name.lower()) - state.bitfields.append("bool " + ":1, ".join(names) + ":1") + if empty: + state.bitfields.append("unsigned int empty_" + str(word) + ":32") + else: + state.bitfields.append("bool " + ":1, ".join(names) + ":1")
There's no need for the extra empty variable (this is python, not C).
if any(names):
state.bitfields.append("bool " + ":1, ".join(names) + ":1") else:
state.bitfields.append("uint32_t empty_%s" % (word, ))
But there's a related bug later in the script which MISRA won't notice unless it happens to run on the cset boundary introducing a new leaf.
I'll see about doing a patch to address both.
~Andrew