Skip to contentSkip to conversation

xen: address violations of MISRA C:2012 Rule 16.3

PATCH In review Federico Serafini 3 participants 6 messages Apr 4, 2024

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 xen/sched: address violations of MISRA C:2012 Rule 16.3

In reply to Federico Serafini

Add break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
Replace deprecated comment /* FALLTHRU */ with pseudo-keyword fallthrough to meet the requirements to deviate the rule.

No functional change.

---
Changes in v2:
- this patch is the result of merging together two different patches with the same title;
- commit message has been improved to make clear that the comment is deprecated.

---
 xen/common/sched/core.c    | 1 +
 xen/common/sched/credit2.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
xen/common/sched/core.c +1 -0
index 3e48da1cdd..0cb33831d2 100644
@@ -2007,6 +2007,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     default:
         ret = -ENOSYS;
+        break;
     }
 
     return ret;
xen/common/sched/credit2.c +1 -1
index c76330d79d..0962b52415 100644
@@ -3152,8 +3152,8 @@ static int cf_check csched2_sys_cntl(
             printk(XENLOG_INFO "Disabling context switch rate limiting\n");
         prv->ratelimit_us = params->ratelimit_us;
         write_unlock_irqrestore(&prv->lock, flags);
+        fallthrough;
 
-    /* FALLTHRU */
     case XEN_SYSCTL_SCHEDOP_getinfo:
         params->ratelimit_us = prv->ratelimit_us;
         break;
Signature · 1 line
2.34.1
#0 lore raw

v2 cover xen: address violations of MISRA C:2012 Rule 16.3

Address violations of MISRA C:2012 Rule 16.3 by adding fallthrough, break and return at the end of the switch-clauses.

Federico Serafini (2):
xen/sched: address violations of MISRA C:2012 Rule 16.3
vsprintf: address violations of MISRA C:2012 Rule 16.3

 xen/common/sched/core.c    | 1 +
 xen/common/sched/credit2.c | 2 +-
 xen/common/vsprintf.c      | 6 +++++-
 3 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 2/2 vsprintf: address violations of MISRA C:2012 Rule 16.3

MISRA C:2012 Rule 16.3 states: "An unconditional `break' statement shall terminate every switch-clause".

In order to meet the requirements to deviate the rule:
1) refactor the for loop to make the switch-clause ending with a return statement (note that adding a break at the end of the switch-clause would result in a violation of Rule 2.1 "A project shall not contain unreachable code");
2) add pseudo-keyword fallthrough.

No functional change.

---
Changes in v2:
- improved commit message.

---
 xen/common/vsprintf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/vsprintf.c +5 -1
index c49631c0a4..612751c90f 100644
@@ -377,7 +377,7 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
             str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD);
 
             if ( ++i == field_width )
-                return str;
+                break;
 
             if ( sep )
             {
@@ -386,6 +386,8 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
                 ++str;
             }
         }
+
+        return str;
     }
 
     case 'p': /* PCI SBDF. */
@@ -619,6 +621,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 
         case 'X':
             flags |= LARGE;
+            fallthrough;
         case 'x':
             base = 16;
             break;
@@ -626,6 +629,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
         case 'd':
         case 'i':
             flags |= SIGN;
+            fallthrough;
         case 'u':
             break;
 
Signature · 1 line
2.34.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [XEN PATCH v2 1/2] xen/sched: address violations of MISRA C:2012 Rule 16.3

In reply to Federico Serafini
Quoted 9 lines · Federico Serafini

Add break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
Replace deprecated comment /* FALLTHRU */ with pseudo-keyword fallthrough to meet the requirements to deviate the rule.

No functional change.

Reviewed-by on v2 2/2
#5 lore raw

Re: [XEN PATCH v2 2/2] vsprintf: address violations of MISRA C:2012 Rule 16.3

In reply to Federico Serafini
Quoted 10 lines · Federico Serafini

MISRA C:2012 Rule 16.3 states: "An unconditional `break' statement shall terminate every switch-clause".

In order to meet the requirements to deviate the rule:
1) refactor the for loop to make the switch-clause ending with a return statement (note that adding a break at the end of the switch-clause would result in a violation of Rule 2.1 "A project shall not contain unreachable code");
2) add pseudo-keyword fallthrough.

Quoted 3 lines

No functional change.

Acked-by on v2 1/2
#3 lore raw

Re: [XEN PATCH v2 1/2] xen/sched: address violations of MISRA C:2012 Rule 16.3

In reply to Federico Serafini
Quoted 10 lines · Federico Serafini

Add break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
Replace deprecated comment /* FALLTHRU */ with pseudo-keyword fallthrough to meet the requirements to deviate the rule.

No functional change.