x86: address violations of MISRA C Rule 16.3
cover x86: address violations of MISRA C Rule 16.3
This patch series addresses violations of MISRA C Rule 16.3 and updates the ECLAIR configuration to consider also hypened fall-through comment as a deviation to the rule.
Federico Serafini (13):
automation/eclair: consider also hypened fall-through x86/cpuid: use fallthrough pseudo keyword x86/domctl: add missing break statement x86/vpmu: address violations of MISRA C Rule 16.3 x86/traps: use fallthrough pseudo keyword x86/mce: add missing break statements x86/hvm: address violations of MISRA C Rule 16.3 x86/vpt: address a violation of MISRA C Rule 16.3 x86/mm: add defensive return
x86/mpparse: add break statement x86/pmtimer: address a violation of MISRA C Rule 16.3 x86/vPIC: address a violation of MISRA C Rule 16.3 x86/vlapic: address a violation of MISRA C Rule 16.3
automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- docs/misra/deviations.rst | 4 ++++ xen/arch/x86/cpu/mcheck/mce_amd.c | 1 + xen/arch/x86/cpu/mcheck/mce_intel.c | 2 ++ xen/arch/x86/cpu/vpmu.c | 3 +++ xen/arch/x86/cpu/vpmu_intel.c | 1 + xen/arch/x86/cpuid.c | 3 +-- xen/arch/x86/domctl.c | 1 + xen/arch/x86/hvm/emulate.c | 3 +++ xen/arch/x86/hvm/hvm.c | 6 ++++++ xen/arch/x86/hvm/hypercall.c | 1 + xen/arch/x86/hvm/irq.c | 1 + xen/arch/x86/hvm/pmtimer.c | 1 + xen/arch/x86/hvm/vlapic.c | 1 + xen/arch/x86/hvm/vpic.c | 1 + xen/arch/x86/hvm/vpt.c | 2 ++ xen/arch/x86/mm.c | 1 + xen/arch/x86/mpparse.c | 1 + xen/arch/x86/traps.c | 3 +++ 19 files changed, 35 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/13 automation/eclair: consider also hypened fall-through
Update ECLAIR configuration to deviate MISRA C Rule 16.3 using different version of hypened fall-through and search for the comment for 2 lines after the last statement.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- docs/misra/deviations.rst | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +1 -1
@@ -400,7 +400,7 @@ safe." -doc_end -doc_begin="Switch clauses ending with an explicit comment indicating the fallthrough intention are safe." --config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"} +-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all[ -]?through.? \\*/.*$,0..2))))"} -doc_end -doc_begin="Switch statements having a controlling expression of enum type deliberately do not have a default case: gcc -Wall enables -Wswitch which warns (and breaks the build as we use -Werror) if one of the enum labels is missing from the switch."
docs/misra/deviations.rst +4 -0
@@ -353,6 +353,10 @@ Deviations related to MISRA C:2012 Rules: However, the use of such comments in new code is deprecated: the pseudo-keyword "fallthrough" shall be used. - Tagged as `safe` for ECLAIR. The accepted comments are: + - /\* fall-through \*/ + - /\* Fall-through. \*/ + - /\* Fall-through \*/ + - /\* fall-through. \*/ - /\* fall through \*/ - /\* fall through. \*/ - /\* fallthrough \*/
Signature · 1 line
2.34.1
Re: [XEN PATCH 01/13] automation/eclair: consider also hypened fall-through
automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 403
Quoted 8 lines · Federico Serafini
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-1@@ -400,7 +400,7 @@ safe." -doc_end -doc_begin="Switch clauses ending with an explicit comment indicating the fallthrough intention are safe." --config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"} +-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all[ -]?through.? \\*/.*$,0..2))))"}
Is is a regex, isn't it? Doesn't the period also need escaping (or enclosing in square brackets)? (I realize it was like this before, but still.)
docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 362
Quoted 13 lines
docs/misra/deviations.rst +4
-0@@ -353,6 +353,10 @@ Deviations related to MISRA C:2012 Rules: However, the use of such comments in new code is deprecated: the pseudo-keyword "fallthrough" shall be used. - Tagged as `safe` for ECLAIR. The accepted comments are: + - /\* fall-through \*/ + - /\* Fall-through. \*/ + - /\* Fall-through \*/ + - /\* fall-through. \*/ - /\* fall through \*/ - /\* fall through. \*/ - /\* fallthrough \*/
Nit: Can the capital-F and non-capital-f variants please be next to each other?
Jan
Re: [XEN PATCH 01/13] automation/eclair: consider also hypened fall-through
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Federico Serafini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -400,7 +400,7 @@ safe." -doc_end
Quoted 6 lines
automation/eclair_analysis/ECLAIR/deviations.ecl safe." · line 403
Quoted 3 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-1-doc_begin="Switch clauses ending with an explicit comment indicating the fallthrough intention are safe." --config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"} +-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all[ -]?through.? \\*/.*$,0..2))))"}Is is a regex, isn't it? Doesn't the period also need escaping (or enclosing in square brackets)? (I realize it was like this before, but still.)
Yes, thanks for noticing.
Quoted 16 lines
Quoted 4 lines
docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 362
Quoted 10 lines
docs/misra/deviations.rst +4
-0@@ -353,6 +353,10 @@ Deviations related to MISRA C:2012 Rules: However, the use of such comments in new code is deprecated: the pseudo-keyword "fallthrough" shall be used. - Tagged as `safe` for ECLAIR. The accepted comments are: + - /\* fall-through \*/ + - /\* Fall-through. \*/ + - /\* Fall-through \*/ + - /\* fall-through. \*/ - /\* fall through \*/ - /\* fall through. \*/ - /\* fallthrough \*/Nit: Can the capital-F and non-capital-f variants please be next to each other?
Ok.
Signature · 3 lines
Federico Serafini, M.Sc. Software Engineer, BUGSENG (http://bugseng.com)
Re: [XEN PATCH 01/13] automation/eclair: consider also hypened fall-through
In reply to Federico SerafiniHi,
Quoted 28 lines · Federico Serafini
Update ECLAIR configuration to deviate MISRA C Rule 16.3 using different version of hypened fall-through and search for the comment for 2 lines after the last statement.
Signed-off-by Federico Serafini <[email protected]>--- automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- docs/misra/deviations.rst | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)automation/eclair_analysis/ECLAIR/deviations.ecl +1
-1@@ -400,7 +400,7 @@ safe." -doc_end -doc_begin="Switch clauses ending with an explicit comment indicating the fallthrough intention are safe." --config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"} +-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all[ -]?through.? \\*/.*$,0..2))))"} -doc_end -doc_begin="Switch statements having a controlling expression of enum type deliberately do not have a default case: gcc -Wall enables -Wswitch which warns (and breaks the build as we use -Werror) if one of the enum labels is missing from the switch."docs/misra/deviations.rst +0
-0
docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 359
Quoted 7 lines
docs/misra/deviations.rst +4
-0@@ -353,6 +353,10 @@ Deviations related to MISRA C:2012 Rules: However, the use of such comments in new code is deprecated: the pseudo-keyword "fallthrough" shall be used. - Tagged as `safe` for ECLAIR. The accepted comments are: + - /\* fall-through \*/ + - /\* Fall-through. \*/ + - /\* Fall-through \*/ + - /\* fall-through. \*/
How many places use the 4 above? The reason I am asking is I am not particularly happy to add yet another set of variant.
I would rather prefer if we settle down with a single comment and therefore convert them to the pseudo-keyword.
Cheers,
Signature · 1 line
Julien Grall
Re: [XEN PATCH 01/13] automation/eclair: consider also hypened fall-through
Quoted 43 lines · Julien Grall
Hi,
Quoted 30 lines · Federico Serafini
Update ECLAIR configuration to deviate MISRA C Rule 16.3 using different version of hypened fall-through and search for the comment for 2 lines after the last statement.
Signed-off-by Federico Serafini <[email protected]>---
automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- docs/misra/deviations.rst | 4 ++++2 files changed, 5 insertions(+), 1 deletion(-)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -400,7 +400,7 @@ safe."-doc_end
-doc_begin="Switch clauses ending with an explicit comment indicating the fallthrough intention are safe." --config=MC3R1.R16.3,reports+={safe,
"any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"} +-config=MC3R1.R16.3,reports+={safe,
"any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all[ -]?through.? \\*/.*$,0..2))))"}
-doc_end
-doc_begin="Switch statements having a controlling expression of enum type deliberately do not have a default case: gcc -Wall enables -Wswitch which warns (and breaks the build as we use -Werror) if one
of the enum labels is missing from the switch."docs/misra/deviations.rst +0
-0@@ -353,6 +353,10 @@ Deviations related to MISRA C:2012 Rules:Quoted 7 lines
However, the use of such comments in new code is deprecated:
the pseudo-keyword "fallthrough" shall be used.
- Tagged assafefor ECLAIR. The accepted comments are:
+ - /\* fall-through \*/
+ - /\* Fall-through. \*/
+ - /\* Fall-through \*/
+ - /\* fall-through. \*/How many places use the 4 above? The reason I am asking is I am not particularly happy to add yet another set of variant.
Quoted 1 line
I would rather prefer if we settle down with a single comment and therefore convert them to the pseudo-keyword.
7 occurrences and 3 of them are in xen/arch/x86/hvm/emulate.c PATCH 07/13 modifies emulate.c anyway, so I could remove them in a v2.
Signature · 3 lines
Federico Serafini, M.Sc. Software Engineer, BUGSENG (http://bugseng.com)
PATCH 2/13 x86/cpuid: use fallthrough pseudo keyword
In reply to Federico SerafiniThe current comment making explicit the fallthrough intention does not follow the agreed syntax: replace it with the pseduo keyword.
No functional change.
--- xen/arch/x86/cpuid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/cpuid.c +1 -2
@@ -97,9 +97,8 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,if (is_viridian_domain (d) )return cpuid_viridian_leaves (v, leaf, subleaf, res); + fallthrough;/* -* Fallthrough. -* * Intel reserve up until 0x4fffffff for hypervisor use. AMD reserve * only until 0x400000ff, but we already use double that. */
Signature · 1 line
2.34.1
PATCH 3/13 x86/domctl: add missing break statement
In reply to Federico SerafiniAdd missing break statement to address a violation of MISRA C Rule 16.3.
No functional change.
--- xen/arch/x86/domctl.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/domctl.c +1 -0
@@ -517,6 +517,7 @@ long arch_do_domctl(default : ret = -ENOSYS ; +break ; }break ; }
Signature · 1 line
2.34.1
PATCH 4/13 x86/vpmu: address violations of MISRA C Rule 16.3
In reply to Federico SerafiniAdd missing break statements to address violations of MISRA C Rule 16.3: "An unconditional `break' statement shall terminate every switch-clause".
No functional change.
--- xen/arch/x86/cpu/vpmu.c | 3 +++ xen/arch/x86/cpu/vpmu_intel.c | 1 + 2 files changed, 4 insertions(+)
xen/arch/x86/cpu/vpmu.c +3 -0
@@ -663,6 +663,8 @@ long do_xenpmu_op(if ( pmu_params.version.maj !=XENPMU_VER_MAJ )return -EINVAL ; + +break ; } switch ( op )
@@ -776,6 +778,7 @@ long do_xenpmu_op(default : ret = -EINVAL ; +break ; }return ret;
xen/arch/x86/cpu/vpmu_intel.c +1 -0
@@ -713,6 +713,7 @@ static int cf_check core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)break ;default :rdmsrl (msr, *msr_content); +break ; } }else if ( msr ==MSR_IA32_MISC_ENABLE )
Signature · 1 line
2.34.1
PATCH 5/13 x86/traps: use fallthrough pseudo keyword
In reply to Federico SerafiniAdd break or pseudo keyword fallthrough to address violations of MISRA C Rule 16.3.
No functional change.
--- xen/arch/x86/traps.c | 3 +++ 1 file changed, 3 insertions(+)
xen/arch/x86/traps.c +3 -0
@@ -1186,6 +1186,7 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,default :ASSERT_UNREACHABLE (); +break ; } }
@@ -1748,6 +1749,7 @@ static void io_check_error(const struct cpu_user_regs *regs) {case 'd' :/* 'dom0' */ nmi_hwdom_report (_XEN_NMIREASON_io_error); + fallthrough;case 'i' :/* 'ignore' */ break ;default :/* 'fatal' */
@@ -1768,6 +1770,7 @@ static void unknown_nmi_error(const struct cpu_user_regs *regs, {case 'd' :/* 'dom0' */ nmi_hwdom_report (_XEN_NMIREASON_unknown); + fallthrough;case 'i' :/* 'ignore' */ break ;default :/* 'fatal' */
Signature · 1 line
2.34.1
PATCH 6/13 x86/mce: add missing break statements
In reply to Federico SerafiniAdd missing break statements to address violations of MISRA C Rule 16.3.
No functional change.
--- xen/arch/x86/cpu/mcheck/mce_amd.c | 1 + xen/arch/x86/cpu/mcheck/mce_intel.c | 2 ++ 2 files changed, 3 insertions(+)
xen/arch/x86/cpu/mcheck/mce_amd.c +1 -0
@@ -201,6 +201,7 @@ static void mcequirk_amd_apply(enum mcequirk_amd_flags flags)default :ASSERT (flags ==MCEQUIRK_NONE ); +break ; } }
xen/arch/x86/cpu/mcheck/mce_intel.c +2 -0
@@ -896,6 +896,8 @@ static void intel_init_ppin(const struct cpuinfo_x86 *c) ppin_msr =0 ; else if ( c == &boot_cpu_data ) ppin_msr =MSR_PPIN ; + +break ; } }
Signature · 1 line
2.34.1
PATCH 7/13 x86/hvm: address violations of MISRA C Rule 16.3
In reply to Federico SerafiniMISRA C Rule 16.3 states that "An unconditional `break' statement shall terminate every switch-clause".
Add pseudo keyword fallthrough and missing break statement to address violations of the rule.
As a defensive measure, return -EOPNOTSUPP in case an unreachable return statement is reached.
--- xen/arch/x86/hvm/emulate.c | 3 +++ xen/arch/x86/hvm/hvm.c | 6 ++++++ xen/arch/x86/hvm/hypercall.c | 1 + xen/arch/x86/hvm/irq.c | 1 + 4 files changed, 11 insertions(+)
xen/arch/x86/hvm/emulate.c +3 -0
@@ -2674,6 +2674,7 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt,default :ASSERT_UNREACHABLE (); +break ; }if ( hvmemul_ctxt->ctxt.retire.singlestep )
@@ -2764,6 +2765,7 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla)/* fallthrough */ default :hvm_emulate_writeback (&ctxt); +break ; }return rc;
@@ -2803,6 +2805,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,default : ctx.set_context = (kind ==EMUL_KIND_SET_CONTEXT_DATA ); rc =hvm_emulate_one (&ctx, VIO_no_completion); +break ; } switch ( rc )
xen/arch/x86/hvm/hvm.c +6 -0
@@ -4919,6 +4919,8 @@ static int do_altp2m_op(default :ASSERT_UNREACHABLE (); + rc = -EOPNOTSUPP ; +break ; } out:
@@ -5020,6 +5022,8 @@ static int compat_altp2m_op(default :ASSERT_UNREACHABLE (); + rc = -EOPNOTSUPP ; +break ; }return rc;
@@ -5283,6 +5287,8 @@ void hvm_get_segment_register(struct vcpu *v, enum x86_segment seg,* %cs and %tr are unconditionally present. SVM ignores these present * bits and will happily run without them set. */ + fallthrough; +case x86_seg_cs: reg->p =1 ;break ;
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -111,6 +111,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)case 8 : eax = regs->rax;/* Fallthrough to permission check. */ + fallthrough;case 4 :case 2 : if ( currd->arch.monitor.guest_request_userspace_enabled &&
xen/arch/x86/hvm/irq.c +1 -0
@@ -282,6 +282,7 @@ static void hvm_set_callback_irq_level(struct vcpu *v)__hvm_pci_intx_assert (d, pdev, pintx); else__hvm_pci_intx_deassert (d ,pdev ,pintx ); +break ;default :break ; }
Signature · 1 line
2.34.1
PATCH 8/13 x86/vpt: address a violation of MISRA C Rule 16.3
In reply to Federico SerafiniAdd pseudo keyword fallthrough to meet the requirements to deviate a violation of MISRA C Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
--- xen/arch/x86/hvm/vpt.c | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/x86/hvm/vpt.c +2 -0
@@ -121,6 +121,8 @@ static int pt_irq_masked(struct periodic_time *pt) }/* Fallthrough to check if the interrupt is masked on the IO APIC. */ + fallthrough; +case PTSRC_ioapic: {int mask =vioapic_get_mask (v->domain, gsi);
Signature · 1 line
2.34.1
PATCH 9/13 x86/mm: add defensive return
In reply to Federico SerafiniAdd defensive return statement at the end of an unreachable default case. Other than improve safety, this meets the requirements to deviate a violation of MISRA C Rule 16.3.
--- xen/arch/x86/mm.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/mm.c +1 -0
@@ -916,6 +916,7 @@ get_page_from_l1e(return 0 ;default :ASSERT_UNREACHABLE (); +return 0 ; } }else if ( l1f & _PAGE_RW )
Signature · 1 line
2.34.1
PATCH 10/13 x86/mpparse: add break statement
In reply to Federico SerafiniAdd a missing break statement to address a violation of MISRA C Rule 16.3.
No functional change.
--- xen/arch/x86/mpparse.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/mpparse.c +1 -0
@@ -544,6 +544,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)case 4 :case 7 :memcpy (bus.mpc_bustype,"MCA " ,6 ); +break ; }MP_bus_info (&bus);if (mpc_default_type >4 ) {
Signature · 1 line
2.34.1
PATCH 11/13 x86/pmtimer: address a violation of MISRA C Rule 16.3
In reply to Federico SerafiniAdd missing break statement to address a violation of MISRA C Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
--- xen/arch/x86/hvm/pmtimer.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/pmtimer.c +1 -0
@@ -185,6 +185,7 @@ static int cf_check handle_evt_io(gdprintk (XENLOG_WARNING ,"Bad ACPI PM register write: %x bytes (%x) at %x\n" , bytes, *val, port); +break ; } }/* Fix up the SCI state to match the new register state */
Signature · 1 line
2.34.1
PATCH 12/13 x86/vPIC: address a violation of MISRA C Rule 16.3
In reply to Federico SerafiniAdd pseudokeyword fallthrough to meet the requirements to deviate a violation of MISRA C Rul 16.3: "An unconditional `break' statement shall terminate every switch-clause".
No functional change.
--- xen/arch/x86/hvm/vpic.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/vpic.c +1 -0
@@ -309,6 +309,7 @@ static void vpic_ioport_write(if ( !(vpic->init_state &8 ) )break ;/* CASCADE mode: wait for write to ICW3. */ /* SNGL mode: fall through (no ICW3). */ + fallthrough;case 2 :/* ICW3 */ vpic->init_state++;
Signature · 1 line
2.34.1
PATCH 13/13 x86/vlapic: address a violation of MISRA C Rule 16.3
In reply to Federico SerafiniAdd missing break statement to address a violation of MISRA C Rule 16.3: "An unconditional `break' statement shall terminate every switch-clause".
No functional change.
--- xen/arch/x86/hvm/vlapic.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/vlapic.c +1 -0
@@ -367,6 +367,7 @@ static void vlapic_accept_irq(struct vcpu *v, uint32_t icr_low)gdprintk (XENLOG_ERR ,"TODO: unsupported delivery mode in ICR %x\n" , icr_low);domain_crash (v->domain); +break ; } }
Signature · 1 line
2.34.1