xen: address violations of MISRA C:2012 Rule 16.3
cover xen: address violations of MISRA C:2012 Rule 16.3
This patch series addresses some violations of Rule 16.3 by adding the missing break statements and pseudo-keyword fallthrough.
Federico Serafini (7):
xen/domctl: address a violation of MISRA C:2012 Rule 16.3
console: address a violation of MISRA C:2012 Rule 16.3 xen/sched: address a violation of MISRA C:2012 Rule 16.3 xen/evtchn: address a violation of MISRA C:2012 Rule 16.3 xen/sched: address a violation of MISRA C:2012 Rule 16.3 xen/vm-event: address a violation of MISRA C:2012 Rule 16.3
vsprintf: address violations of MISRA C:2012 Rule 16.3
xen/common/domctl.c | 1 + xen/common/event_channel.c | 1 + xen/common/sched/core.c | 1 + xen/common/sched/credit2.c | 2 +- xen/common/vm_event.c | 1 + xen/common/vsprintf.c | 6 +++++- xen/drivers/char/console.c | 2 ++ 7 files changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 2/7 console: address a violation of MISRA C:2012 Rule 16.3
Add break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause ").
No functional change.
--- xen/drivers/char/console.c | 2 ++ 1 file changed, 2 insertions(+)
xen/drivers/char/console.c +2 -0
@@ -568,6 +568,8 @@ static void __serial_rx(char c)if ( d !=NULL )rcu_unlock_domain (d); + + break; }#endif }
Signature · 1 line
2.34.1
PATCH 3/7 xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniUse pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/credit2.c +1 -1
@@ -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
PATCH 5/7 xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniAdd break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause ").
No functional change.
--- xen/common/sched/core.c | 1 + 1 file changed, 1 insertion(+)
xen/common/sched/core.c +1 -0
@@ -2007,6 +2007,7 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)default : ret = -ENOSYS ; +break ; }return ret;
Signature · 1 line
2.34.1
PATCH 1/7 xen/domctl: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniAdd break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause ").
No functional change.
--- xen/common/domctl.c | 1 + 1 file changed, 1 insertion(+)
xen/common/domctl.c +1 -0
@@ -316,6 +316,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) d =rcu_lock_domain_by_id (op->domain);if ( !d )return -ESRCH ; +break ; } ret =xsm_domctl (XSM_OTHER , d, op->cmd);
Signature · 1 line
2.34.1
PATCH 4/7 xen/evtchn: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniAdd break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause ").
No functional change.
--- xen/common/event_channel.c | 1 + 1 file changed, 1 insertion(+)
xen/common/event_channel.c +1 -0
@@ -853,6 +853,7 @@ int evtchn_send(struct domain *ld, unsigned int lport)break ;default : ret = -EINVAL ; +break ; } out:
Signature · 1 line
2.34.1
PATCH 6/7 xen/vm-event: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniAdd break statement to address a violation of MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause ").
No functional change.
--- xen/common/vm_event.c | 1 + 1 file changed, 1 insertion(+)
xen/common/vm_event.c +1 -0
@@ -770,6 +770,7 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)default : rc = -ENOSYS ; +break ; }return rc;
Signature · 1 line
2.34.1
PATCH 7/7 vsprintf: address violations of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniMISRA C:2012 Rule 16.3 states: "An unconditional `break' statement shall terminate every switch-clause".
Add break statement to address violations of the rule or add pseudo-keyword fallthrough to meet the requirements to deviate it.
No functional change.
--- xen/common/vsprintf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/vsprintf.c +5 -1
@@ -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
Re: [XEN PATCH 6/7] xen/vm-event: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 8 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 ").
No functional change.
Signed-off-by Federico Serafini <[email protected]>
Re: [XEN PATCH 1/7] xen/domctl: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 7 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 ").
No functional change.
Signed-off-by Federico Serafini <[email protected]>
Re: [XEN PATCH 2/7] console: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 7 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 ").
No functional change.
Signed-off-by Federico Serafini <[email protected]>
Re: [XEN PATCH 3/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 16 lines · Federico Serafini
Use pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
Signed-off-by Federico Serafini <[email protected]>--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/credit2.c +0
-0
xen/common/sched/credit2.c static int cf_check csched2_sys_cntl( · line 3159
Quoted 9 lines
xen/common/sched/credit2.c +1
-1@@ -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 ;
Hmm, the description doesn't say what's wrong with the comment. Furthermore docs/misra/rules.rst doesn't mention "fallthrough" at all, nor the alternative of using comments. I notice docs/misra/deviations.rst does, and there the specific comment used here isn't covered. That would want saying in the description.
Stefano (and others) - in this context it becomes noticeable that having stuff scattered across multiple doc files isn't necessarily helpful. Other permissible keywords are mentioned in rules.rst. The pseudo-keyword "fallthrough" as well as comments are mentioned on deviations.rst. Could you remind me of the reason(s) why things aren't recorded in a single, central place?
Jan
Re: [XEN PATCH 4/7] xen/evtchn: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 7 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 ").
No functional change.
Signed-off-by Federico Serafini <[email protected]>
Re: [XEN PATCH 5/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 7 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 ").
No functional change.
Signed-off-by Federico Serafini <[email protected]>
However, this is the 2nd patch in this series with exactly the same title. Going just from titles, one option would be to fold both. The other option would be to change the title prefix of patch 3 to "xen/credit2:".
Jan
Re: [XEN PATCH 7/7] vsprintf: address violations of MISRA C:2012 Rule 16.3
In reply to Federico SerafiniQuoted 5 lines · Federico Serafini
MISRA C:2012 Rule 16.3 states: "An unconditional `break' statement shall terminate every switch-clause".
Add break statement to address violations of the rule or add pseudo-keyword fallthrough to meet the requirements to deviate it.
While the latter half of the sentence properly describes the latter two of the hunks, the former half doesn't match the former two hunks at all:
xen/common/vsprintf.c static char *pointer(char *str, const char *end, const char **fmt_ptr, · line 380
Quoted 8 lines
xen/common/vsprintf.c +1
-1@@ -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 ;
This "break" is inside for(), not switch().
xen/common/vsprintf.c static char *pointer(char *str, const char *end, const char **fmt_ptr, · line 391
Quoted 7 lines
xen/common/vsprintf.c +2
-0@@ -386,6 +386,8 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr, ++str; } } + +return str; }
And this "return" is what now "delimits" case 'h' of the switch(). The original situation therefore was that the for() could not be exited by other than the "return" inside. The supposedly missing "break" in that arrangement would have been "unreachable code", i.e. violate another rule. Hence the (undescribed) further re-arrangement.
Jan
Re: [XEN PATCH 5/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 6 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 ").
No functional change.
Quoted 7 lines
Quoted 1 line
Signed-off-by Federico Serafini <[email protected]>Reviewed-by Jan Beulich <[email protected]>However, this is the 2nd patch in this series with exactly the same title. Going just from titles, one option would be to fold both. The other option would be to change the title prefix of patch 3 to "xen/credit2:".
I'll go for the first option.
Signature · 3 lines
Federico Serafini, M.Sc. Software Engineer, BUGSENG (http://bugseng.com)
Re: [XEN PATCH 7/7] vsprintf: address violations of MISRA C:2012 Rule 16.3
In reply to Jan BeulichQuoted 22 lines · Jan Beulich
Quoted 5 lines · Federico Serafini
MISRA C:2012 Rule 16.3 states: "An unconditional `break' statement shall terminate every switch-clause".
Add break statement to address violations of the rule or add pseudo-keyword fallthrough to meet the requirements to deviate it.
While the latter half of the sentence properly describes the latter two of the hunks, the former half doesn't match the former two hunks at all:
xen/common/vsprintf.c static char *pointer(char *str, const char *end, const char **fmt_ptr, · line 380
Quoted 8 lines
xen/common/vsprintf.c +1
-1@@ -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 ;This "break" is inside
for(), notswitch().
Quoted 13 lines
xen/common/vsprintf.c static char *pointer(char *str, const char *end, const char **fmt_ptr, · line 391
Quoted 7 lines
xen/common/vsprintf.c +2
-0@@ -386,6 +386,8 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr, ++str; } } + +return str; }And this "return" is what now "delimits" case 'h' of the
switch(). The original situation therefore was that thefor()could not be exited by other than the "return" inside. The supposedly missing "break" in that arrangement would have been "unreachable code", i.e. violate another rule. Hence the (undescribed) further re-arrangement.
I'll improve the description.
Signature · 3 lines
Federico Serafini, M.Sc. Software Engineer, BUGSENG (http://bugseng.com)
Re: [XEN PATCH 3/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
In reply to Jan BeulichQuoted 34 lines · Jan Beulich
Quoted 25 lines · Federico Serafini
Use pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
Signed-off-by Federico Serafini <[email protected]>--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/credit2.c +1
-1@@ -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;Quoted 1 line
break;Hmm, the description doesn't say what's wrong with the comment. Furthermore
docs/misra/rules.rstdoesn't mention "fallthrough" at all, nor the alternative of using comments. I noticedocs/misra/deviations.rstdoes, and there the specific comment used here isn't covered. That would want saying in the description.
Quoted 8 lines
Stefano (and others) - in this context it becomes noticeable that having stuff scattered across multiple doc files isn't necessarily helpful. Other permissible keywords are mentioned in
rules.rst. The pseudo-keyword "fallthrough" as well as comments are mentioned ondeviations.rst. Could you remind me of the reason(s) why things aren't recorded in a single, central place?Jan
If I recall correctly, the idea was to avoid rules.rst from getting too long and too specific about which patterns were deviated, while also having a precise record of the MISRA deviations that didn't live in ECLAIR-specific files. Maybe the use of the pseudo-keyword emerged after the rule was added to rules.rst, since deviations.rst is updated more frequently.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 3/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Jan Beulich
Quoted 25 lines · Federico Serafini
Use pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
Signed-off-by Federico Serafini <[email protected]>--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/credit2.c +1
-1@@ -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;Quoted 1 line
break;Hmm, the description doesn't say what's wrong with the comment. Furthermore
docs/misra/rules.rstdoesn't mention "fallthrough" at all, nor the alternative of using comments. I noticedocs/misra/deviations.rstdoes, and there the specific comment used here isn't covered. That would want saying in the description.Stefano (and others) - in this context it becomes noticeable that having stuff scattered across multiple doc files isn't necessarily helpful. Other permissible keywords are mentioned in
rules.rst. The pseudo-keyword "fallthrough" as well as comments are mentioned ondeviations.rst. Could you remind me of the reason(s) why things aren't recorded in a single, central place?
Quoted 7 lines
Quoted 1 line
Jan
If I recall correctly, the idea was to avoid
rules.rstfrom getting too long and too specific about which patterns were deviated, while also having a precise record of the MISRA deviations that didn't live in ECLAIR-specific files. Maybe the use of the pseudo-keyword emerged after the rule was added torules.rst, sincedeviations.rstis updated more frequently.
Yes exactly.
I agree with Jan that a single central place is easiest but we cannot move everything that is in deviations.rst in the note section of the rules.rst table. Of the two, it would be best to reduce the amount of notes in rules.rst and move all the deviations listed in rules.rst to deviations.rst. That way at least the info is present only once, although they are 2 files.
Re: [XEN PATCH 3/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
Quoted 51 lines · Stefano Stabellini
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Jan Beulich
Quoted 25 lines · Federico Serafini
Use pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
Signed-off-by Federico Serafini <[email protected]>--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/credit2.c +1
-1@@ -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;Quoted 1 line
break;Hmm, the description doesn't say what's wrong with the comment. Furthermore
docs/misra/rules.rstdoesn't mention "fallthrough" at all, nor the alternative of using comments. I noticedocs/misra/deviations.rstdoes, and there the specific comment used here isn't covered. That would want saying in the description.Stefano (and others) - in this context it becomes noticeable that having stuff scattered across multiple doc files isn't necessarily helpful. Other permissible keywords are mentioned in
rules.rst. The pseudo-keyword "fallthrough" as well as comments are mentioned ondeviations.rst. Could you remind me of the reason(s) why things aren't recorded in a single, central place?Quoted 7 lines
Quoted 1 line
Jan
If I recall correctly, the idea was to avoid
rules.rstfrom getting too long and too specific about which patterns were deviated, while also having a precise record of the MISRA deviations that didn't live in ECLAIR-specific files. Maybe the use of the pseudo-keyword emerged after the rule was added torules.rst, sincedeviations.rstis updated more frequently.
Quoted 8 lines
Yes exactly.
I agree with Jan that a single central place is easiest but we cannot move everything that is in
deviations.rstin the note section of therules.rsttable. Of the two, it would be best to reduce the amount of notes inrules.rstand move all the deviations listed inrules.rsttodeviations.rst. That way at least the info is present only once, although they are 2 files.
Could every rules.rst section having a deviations.rst counterpart then perhaps have a standardized referral to there?
Jan
Re: [XEN PATCH 3/7] xen/sched: address a violation of MISRA C:2012 Rule 16.3
Quoted 61 lines · Jan Beulich
Quoted 51 lines · Stefano Stabellini
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Jan Beulich
Quoted 25 lines · Federico Serafini
Use pseudo-keyword fallthrough to meet the requirements to deviate MISRA C:2012 Rule 16.3 ("An unconditional `break' statement shall terminate every switch-clause").
No functional change.
Signed-off-by Federico Serafini <[email protected]>--- xen/common/sched/credit2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/credit2.c +1
-1@@ -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;Quoted 1 line
break;Hmm, the description doesn't say what's wrong with the comment. Furthermore
docs/misra/rules.rstdoesn't mention "fallthrough" at all, nor the alternative of using comments. I noticedocs/misra/deviations.rstdoes, and there the specific comment used here isn't covered. That would want saying in the description.Stefano (and others) - in this context it becomes noticeable that having stuff scattered across multiple doc files isn't necessarily helpful. Other permissible keywords are mentioned in
rules.rst. The pseudo-keyword "fallthrough" as well as comments are mentioned ondeviations.rst. Could you remind me of the reason(s) why things aren't recorded in a single, central place?Quoted 7 lines
Quoted 1 line
Jan
If I recall correctly, the idea was to avoid
rules.rstfrom getting too long and too specific about which patterns were deviated, while also having a precise record of the MISRA deviations that didn't live in ECLAIR-specific files. Maybe the use of the pseudo-keyword emerged after the rule was added torules.rst, sincedeviations.rstis updated more frequently.Quoted 8 lines
Yes exactly.
I agree with Jan that a single central place is easiest but we cannot move everything that is in
deviations.rstin the note section of therules.rsttable. Of the two, it would be best to reduce the amount of notes inrules.rstand move all the deviations listed inrules.rsttodeviations.rst. That way at least the info is present only once, although they are 2 files.
Quoted 2 lines
Could every
rules.rstsection having adeviations.rstcounterpart then perhaps have a standardized referral to there?
+1