]> xenbits.xensource.com Git - xen.git/commitdiff
xen/x86: resolve the last 3 MISRA R16.6 violations
authorStefano Stabellini <stefano.stabellini@amd.com>
Thu, 20 Feb 2025 21:32:46 +0000 (13:32 -0800)
committerStefano Stabellini <stefano.stabellini@amd.com>
Thu, 20 Feb 2025 21:32:46 +0000 (13:32 -0800)
MISRA R16.6 states that "Every switch statement shall have at least two
switch-clauses". There are only 3 violations left on x86 (zero on ARM).

One of them is only a violation depending on the kconfig configuration.
So deviate it instead with a SAF comment.

Two of them are deliberate to enable future additions. Deviate them as
such.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-Acked-By: Oleksii Kurochko <oleksii.kurochko@gmail.com>
docs/misra/safe.json
xen/arch/x86/hvm/hvm.c
xen/arch/x86/traps.c

index b8a4f878ea2fc3b765c5f42f1a05876ee2d433c9..3d68b591696eda5516fd0b1d18efcd44586ef5b8 100644 (file)
         },
         {
             "id": "SAF-11-safe",
+            "analyser": {
+                "eclair": "MC3A2.R16.6"
+            },
+            "name": "Rule 16.6: single clause due to kconfig",
+            "text": "A switch statement with a single switch clause because other switch clauses are disabled in a given kconfig is safe."
+        },
+        {
+            "id": "SAF-12-safe",
+            "analyser": {
+                "eclair": "MC3A2.R16.6"
+            },
+            "name": "Rule 16.6: single clause due to future expansion",
+            "text": "A switch statement with a single switch clause to purposely enable future additions of new cases is safe."
+        },
+        {
+            "id": "SAF-13-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
index 39e39ce4ce36475baf6767d79e72d7b49e25e99a..0f0630769befb5b5eb788cc96ca766073e5d0513 100644 (file)
@@ -3797,6 +3797,7 @@ uint64_t hvm_get_reg(struct vcpu *v, unsigned int reg)
 {
     ASSERT(v == current || !vcpu_runnable(v));
 
+    /* SAF-12-safe */
     switch ( reg )
     {
     default:
@@ -3808,6 +3809,7 @@ void hvm_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)
 {
     ASSERT(v == current || !vcpu_runnable(v));
 
+    /* SAF-12-safe */
     switch ( reg )
     {
     default:
index 87b30ce4df2a6ff8ac9d622360a5a7ae50a30f4b..dca11a613dbd2ade3993c58ec4e321a28b354ff1 100644 (file)
@@ -436,6 +436,7 @@ unsigned long get_stack_trace_bottom(unsigned long sp)
 
 static unsigned long get_shstk_bottom(unsigned long sp)
 {
+    /* SAF-11-safe */
     switch ( get_stack_page(sp) )
     {
 #ifdef CONFIG_XEN_SHSTK