Skip to contentSkip to conversation

address violations of MISRA C Rule 16.2

PATCH In review Nicola Vetrini 2 participants 5 messages Apr 17, 2024 – Apr 18, 2024

lore
Share & tools
lore
#0 lore raw

v3 cover address violations of MISRA C Rule 16.2

A respin of the last two patches from the previous series.
No changes other than the different SAF comment id because SAF-4-safe was already taken.

Nicola Vetrini (2):
xen/domctl: address violations of MISRA C Rule 16.2
eclair_analysis: deviate x86 emulator for Rule 16.2

 automation/eclair_analysis/ECLAIR/deviations.ecl | 7 +++++++
 docs/misra/deviations.rst                        | 6 ++++++
 docs/misra/safe.json                             | 8 ++++++++
 xen/common/domain.c                              | 1 +
 4 files changed, 22 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 xen/domctl: address violations of MISRA C Rule 16.2

Refactor the first clauses so that a violation of
MISRA C Rule 16.2 is resolved (a switch label should be immediately enclosed in the compound statement of the switch).
Note that the switch clause ending with the pseudo keyword "fallthrough" is an allowed exception to Rule 16.3.

Convert fallthrough comments in other clauses to the pseudo-keyword while at it.

No functional change.

---
 docs/misra/safe.json | 8 ++++++++
 xen/common/domain.c  | 1 +
 2 files changed, 9 insertions(+)
docs/misra/safe.json +8 -0
index fe2bc185097d..9b13bcf71706 100644
@@ -44,6 +44,14 @@
         },
         {
             "id": "SAF-5-safe",
+            "analyser": {
+                "eclair": "MC3R1.R16.2"
+            },
+            "name": "MC3R1.R16.2: using a case label when the most closely-enclosing compound statement is not a switch statement",
+            "text": "A switch label enclosed by some compound statement that is not the body of a switch is permitted within local helper macros that are unlikely to be misused or misunderstood."
+        },
+        {
+            "id": "SAF-6-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
xen/common/domain.c +1 -0
index 282c3ab62308..1e555d658c97 100644
@@ -457,6 +457,7 @@ static int domain_teardown(struct domain *d)
 
         for_each_vcpu ( d, v )
         {
+            /* SAF-5-safe MISRA C Rule 16.2: switch label enclosed by for loop*/
             PROGRESS_VCPU(teardown);
 
             rc = vcpu_teardown(v);
Signature · 1 line
2.34.1
#2 lore raw

Re: [XEN PATCH v3 1/2] xen/domctl: address violations of MISRA C Rule 16.2

Quoted 6 lines · Nicola Vetrini

Refactor the first clauses so that a violation of
MISRA C Rule 16.2 is resolved (a switch label should be immediately enclosed in the compound statement of the switch).
Note that the switch clause ending with the pseudo keyword "fallthrough" is an allowed exception to Rule 16.3.

Quoted 7 lines

Convert fallthrough comments in other clauses to the pseudo-keyword while at it.

No functional change.

I did ack a patch with this title, yes, but the content of that patch was different. Besides all the references to the fallthrough pseudo- keyword being unrelated to the change below, there's also nothing ...

xen/common/domain.c static int domain_teardown(struct domain *d) · line 463

Quoted 10 lines
xen/common/domain.c +1 -0
@@ -457,6 +457,7 @@ static int domain_teardown(struct domain *d)
 
         for_each_vcpu ( d, v )
         {
+            /* SAF-5-safe MISRA C Rule 16.2: switch label enclosed by for loop*/
             PROGRESS_VCPU(teardown);
 
             rc = vcpu_teardown(v);

... domctl-ish in here. What is going on?

Jan

#3 lore raw

Re: [XEN PATCH v3 1/2] xen/domctl: address violations of MISRA C Rule 16.2

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

Refactor the first clauses so that a violation of
MISRA C Rule 16.2 is resolved (a switch label should be immediately enclosed in the compound statement of the switch).
Note that the switch clause ending with the pseudo keyword "fallthrough" is an allowed exception to Rule 16.3.

Quoted 7 lines

Convert fallthrough comments in other clauses to the pseudo-keyword while at it.

No functional change.

I did ack a patch with this title, yes, but the content of that patch was different. Besides all the references to the fallthrough pseudo- keyword being unrelated to the change below, there's also nothing ...

Quoted 10 lines
xen/common/domain.c +1 -0
@@ -457,6 +457,7 @@ static int domain_teardown(struct domain *d)
 
         for_each_vcpu ( d, v )
         {
+            /* SAF-5-safe MISRA C Rule 16.2: switch label enclosed by 

for loop*/

             PROGRESS_VCPU(teardown);
Quoted 5 lines
Quoted 1 line
             rc = vcpu_teardown(v);

... domctl-ish in here. What is going on?

Jan

Oh, I must have edited the wrong patch when doing v3. Sorry about that. The patch was this [1], just with the id changed.

[1] https://lore.kernel.org/xen-devel/2328b1a43f8bc4c9a9303c46f8eba2847c67a713.1712305581.git.nicola.vetrini@bugseng.com/

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

PATCH v3 2/2 eclair_analysis: deviate x86 emulator for Rule 16.2

In reply to Nicola Vetrini

MISRA C Rule 16.2 states:
"A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement".

Since complying with this rule of the x86 emulator would lead to a lot of code duplication, it is deemed better to exempt those files for this guideline.

No functional change.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 7 +++++++
 docs/misra/deviations.rst                        | 6 ++++++
 2 files changed, 13 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +7 -0
index 0230b41c6d1c..190f6a2fd4e0 100644
@@ -358,6 +358,13 @@ therefore have the same behavior of a boolean"
 # Series 16.
 #
 
+-doc_begin="Complying with the Rule would entail a lot of code duplication in the implementation of the x86 emulator,
+therefore it is deemed better to leave such files as is."
+-file_tag+={x86_emulate,"^xen/arch/x86/x86_emulate/.*$"}
+-file_tag+={x86_svm_emulate,"^xen/arch/x86/hvm/svm/emulate\\.c$"}
+-config=MC3R1.R16.2,reports+={deliberate, "any_area(any_loc(file(x86_emulate||x86_svm_emulate)))"}
+-doc_end
+
 -doc_begin="Switch clauses ending with continue, goto, return statements are
 safe."
 -config=MC3R1.R16.3,terminals+={safe, "node(continue_stmt||goto_stmt||return_stmt)"}
docs/misra/deviations.rst +6 -0
index 32b02905d19a..ed0c1e8ed0bf 100644
@@ -296,6 +296,12 @@ Deviations related to MISRA C:2012 Rules:
        therefore have the same behavior of a boolean.
      - Project-wide deviation; tagged as `deliberate` for ECLAIR.
 
+   * - R16.2
+     - Complying with the Rule would entail a lot of code duplication in the
+       implementation of the x86 emulator, therefore it is deemed better to
+       leave such files as is.
+     - Tagged as `deliberate` for ECLAIR.
+
    * - R16.3
      - Switch clauses ending with continue, goto, return statements are safe.
      - Tagged as `safe` for ECLAIR.
Signature · 1 line
2.34.1