xen/keyhandler: add missing noreturn attribute
PATCH 1/3 xen/keyhandler: add missing noreturn attribute
From: Nicola Vetrini <[email protected]>
Function reboot_machine' does not return, but lacks the noreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".
No functional change.
---
Cc: Andrew Cooper <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: Michal Orzel <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Nicola Vetrini <[email protected]>
Cc: Federico Serafini <[email protected]>
Cc: Bertrand Marquis <[email protected]>
---
xen/common/keyhandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/keyhandler.c +1 -1
@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {printk ("'%c' pressed -> rebooting machine\n" , key);machine_restart (0 );
--
2.25.1
PATCH 2/3 xen/arm: add missing noreturn attributes
From: Nicola Vetrini <[email protected]>
The marked functions never return to their caller, but lack the `noreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".
No functional change.
---
Cc: Andrew Cooper <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: Michal Orzel <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Nicola Vetrini <[email protected]>
Cc: Federico Serafini <[email protected]>
Cc: Bertrand Marquis <[email protected]>
---
xen/arch/arm/efi/efi-boot.h | 2 +- xen/arch/arm/include/asm/arm64/traps.h | 2 +- xen/arch/arm/include/asm/processor.h | 2 +- xen/arch/arm/setup.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/efi/efi-boot.h +1 -1
@@ -934,7 +934,7 @@ static void __init efi_arch_blexit(void) efi_bs->FreePool (memmap); } -static void __init efi_arch_halt (void ) +static void noreturn__init efi_arch_halt (void ) {stop_cpu (); }
xen/arch/arm/include/asm/arm64/traps.h +1 -1
@@ -6,7 +6,7 @@ void inject_undef64_exception(struct cpu_user_regs *regs);void do_sysreg (struct cpu_user_regs *regs,const union hsr hsr); -void do_bad_mode (struct cpu_user_regs *regs,int reason); +void noreturndo_bad_mode (struct cpu_user_regs *regs,int reason);#endif /* __ASM_ARM64_TRAPS__ */ /*
xen/arch/arm/include/asm/processor.h +1 -1
@@ -571,7 +571,7 @@ extern register_t __cpu_logical_map[];#endif #ifndef __ASSEMBLY__ -void panic_PAR (uint64_t par); +void noreturnpanic_PAR (uint64_t par);/* Debugging functions are declared with external linkage to aid development. */ void show_registers (const struct cpu_user_regs *regs);
xen/arch/arm/setup.c +1 -1
@@ -63,7 +63,7 @@ bool __read_mostly acpi_disabled;domid_t __read_mostly max_init_domid; -static __used void init_done (void ) +static __used void noreturninit_done (void ) {int rc;
--
2.25.1
PATCH 3/3 xen/x86: add missing noreturn attributes
From: Nicola Vetrini <[email protected]>
The marked functions never return to their caller, but lack the `noreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".
No functional change.
---
Cc: Andrew Cooper <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: Michal Orzel <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Nicola Vetrini <[email protected]>
Cc: Federico Serafini <[email protected]>
Cc: Bertrand Marquis <[email protected]>
---
xen/arch/x86/cpu/mcheck/mce.c | 3 ++- xen/arch/x86/efi/efi-boot.h | 2 +- xen/arch/x86/smp.c | 2 +- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/traps.c | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +2 -1
@@ -79,7 +79,8 @@ static int __init cf_check mce_set_verbosity(const char *str)custom_param ("mce_verbosity" , mce_set_verbosity);/* Handle unconfigured int18 (should never happen) */ -static void cf_check unexpected_machine_check(const struct cpu_user_regs *regs) +static void noreturn cf_check +unexpected_machine_check (const struct cpu_user_regs *regs) {console_force_unlock ();printk ("Unexpected Machine Check Exception\n" );
xen/arch/x86/efi/efi-boot.h +1 -1
@@ -769,7 +769,7 @@ static void __init efi_arch_blexit(void) efi_bs->FreePages (ucode.addr,PFN_UP (ucode.size)); } -static void __init efi_arch_halt (void ) +static void noreturn__init efi_arch_halt (void ) {local_irq_disable ();for ( ; ; )
xen/arch/x86/smp.c +1 -1
@@ -343,7 +343,7 @@ void __stop_this_cpu(void)cpumask_clear_cpu (smp_processor_id (), &cpu_online_map); } -static void cf_check stop_this_cpu(void *dummy) +static void noreturn cf_check stop_this_cpu(void *dummy) {const bool *stop_aps = dummy;
xen/arch/x86/traps.c +1 -1
@@ -805,7 +805,7 @@ void fatal_trap(const struct cpu_user_regs *regs, bool show_remote) (regs->eflags & X86_EFLAGS_IF) ? "" : " IN INTERRUPT CONTEXT"); } -void asmlinkage do_unhandled_trap(struct cpu_user_regs *regs) +void asmlinkage noreturn do_unhandled_trap(struct cpu_user_regs *regs) {fatal_trap (regs, false); }
xen/arch/x86/x86_64/traps.c +1 -1
@@ -293,7 +293,7 @@ void show_page_walk(unsigned long addr) l1_table_offset(addr), l1e_get_intpte(l1e), pfn); } -void asmlinkage do_double_fault(struct cpu_user_regs *regs) +void asmlinkage noreturn do_double_fault(struct cpu_user_regs *regs) {unsigned int cpu;struct extra_state state;
--
2.25.1
Re: [PATCH 3/3] xen/x86: add missing noreturn attributes
Quoted 10 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
The marked functions never return to their caller, but lack the `noreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>Signed-off-by Victor Lira <[email protected]>
I expect the comment on patch 1 applies to some or all of the cases here, too. For example, I expect that even if efi_arch_halt() wasn't inlined into its sole caller, the compiler would also be able to infer noreturn from the infinite loop there.
Jan
Quoted 5 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".
Is this (uniformly) true? Looking at ...
xen/common/keyhandler.c static void cf_check dump_hwdom_registers(unsigned char key) · line 257
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {printk ("'%c' pressed -> rebooting machine\n" , key);machine_restart (0 );
... generated code here, I can see that the compiler is perfectly able to leverage the noreturn that machine_restart() has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.
That said, I certainly don't mind the addition of the (seemingly) missing attribute. Otoh I wonder whether an attribute the removal of which has no effect wouldn't count as "dead code" or alike, violating some other rule.
Jan
Quoted 29 lines · Jan Beulich
Quoted 5 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".Is this (uniformly) true? Looking at ...
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {Quoted 2 lines
printk("'%c' pressed -> rebooting machine\n", key); machine_restart(0);... generated code here, I can see that the compiler is perfectly able to leverage the noreturn that
machine_restart()has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.
Quoted 4 lines
That said, I certainly don't mind the addition of the (seemingly) missing attribute. Otoh I wonder whether an attribute the removal of which has no effect wouldn't count as "dead code" or alike, violating some other rule.
Inlining does not play a role in this case. Here reboot_machine() is marked as a violation because machine_restart() is noreturn and there is no other path upon which reboot_machine() may return, hence any function calling reboot_machine() could have portions that are inadvertently unreachable (as in never executed due to divergence) by not having the annotation. That said, in such trivial cases compilers are typically able to derive the property automatically, but they are not obliged to and, more importantly, the behavior may even differ with the same compiler using different optimization levels.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Quoted 30 lines · Nicola Vetrini
Quoted 29 lines · Jan Beulich
Quoted 5 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute, therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain unreachable code".Is this (uniformly) true? Looking at ...
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {Quoted 2 lines
printk("'%c' pressed -> rebooting machine\n", key); machine_restart(0);... generated code here, I can see that the compiler is perfectly able to leverage the noreturn that
machine_restart()has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.
Quoted 6 lines
Quoted 4 lines
That said, I certainly don't mind the addition of the (seemingly) missing attribute. Otoh I wonder whether an attribute the removal of which has no effect wouldn't count as "dead code" or alike, violating some other rule.
Inlining does not play a role in this case. Here
reboot_machine()is marked as a violation becausemachine_restart()is noreturn and there is no other path upon whichreboot_machine()may return, hence any function callingreboot_machine()could have portions that are inadvertently unreachable (as in never executed due to divergence) by not having the annotation. That said, in such trivial cases compilers are typically able to derive the property automatically, but they are not obliged to and, more importantly, the behavior may even differ with the same compiler using different optimization levels.
Just a note: in later revisions of MISRA C this has become a rule of its own [1], which helps reduce confusion, but up to MISRA C:2012 Amendment 2 (currently used by Xen), this is part of Rule 2.1.
[1] Rule 17.11: "A function that never returns should be declared with a _Noreturn function specifier"
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Nicola Vetrini
Quoted 39 lines · Jan Beulich
Quoted 7 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute,
therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain
unreachable code".Is this (uniformly) true? Looking at ...
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {Quoted 2 lines
printk("'%c' pressed -> rebooting machine\n", key); machine_restart(0);... generated code here, I can see that the compiler is perfectly able to
leverage the noreturn thatmachine_restart()has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.That said, I certainly don't mind the addition of the (seemingly) missing
attribute. Otoh I wonder whether an attribute the removal of which has no
effect wouldn't count as "dead code" or alike, violating some other rule.
Quoted 6 lines
Quoted 6 lines
Inlining does not play a role in this case. Here
reboot_machine()is marked as a violation becausemachine_restart()is noreturn and there is no other path upon whichreboot_machine()may return, hence any function callingreboot_machine()could have portions that are inadvertently unreachable (as in never executed due to divergence) by not having the annotation.
Just that there's not going to be a 2nd caller, considering the purpose of the function.
Quoted 11 lines
Quoted 4 lines
That said, in such trivial cases compilers
are typically able to derive the property automatically, but they are not obliged to and, more importantly, the behavior may even differ with the same compiler using different optimization levels.Just a note: in later revisions of MISRA C this has become a rule of its own [1], which helps reduce confusion, but up to MISRA C:2012 Amendment 2 (currently used by Xen), this is part of Rule 2.1.
[1] Rule 17.11: "A function that never returns should be declared with a
_Noreturnfunction specifier"
Oh, that's indeed quite a bit more explicit.
Jan
Quoted 58 lines · Jan Beulich
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Nicola Vetrini
Quoted 39 lines · Jan Beulich
Quoted 7 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute,
therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain
unreachable code".Is this (uniformly) true? Looking at ...
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {Quoted 2 lines
printk("'%c' pressed -> rebooting machine\n", key); machine_restart(0);... generated code here, I can see that the compiler is perfectly able to
leverage the noreturn thatmachine_restart()has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.That said, I certainly don't mind the addition of the (seemingly) missing
attribute. Otoh I wonder whether an attribute the removal of which has no
effect wouldn't count as "dead code" or alike, violating some other rule.Quoted 6 lines
Quoted 6 lines
Inlining does not play a role in this case. Here
reboot_machine()is marked as a violation becausemachine_restart()is noreturn and there is no other path upon whichreboot_machine()may return, hence any function callingreboot_machine()could have portions that are inadvertently unreachable (as in never executed due to divergence) by not having the annotation.Just that there's not going to be a 2nd caller, considering the purpose of the function.
Quoted 5 lines
Quoted 4 lines
That said, in such trivial cases compilers
are typically able to derive the property automatically, but they are not obliged to and, more importantly, the behavior may even differ with the same compiler using different optimization levels.
Quoted 8 lines
Quoted 6 lines
Just a note: in later revisions of MISRA C this has become a rule of its own [1], which helps reduce confusion, but up to MISRA C:2012 Amendment 2 (currently used by Xen), this is part of Rule 2.1.
[1] Rule 17.11: "A function that never returns should be declared with a
_Noreturnfunction specifier"Oh, that's indeed quite a bit more explicit.
Does it mean you would ack the patch? :-)
Quoted 63 lines · Stefano Stabellini
Quoted 62 lines · Jan Beulich
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Nicola Vetrini
Quoted 39 lines · Jan Beulich
Quoted 7 lines · On 05.06.2025 01:49, [email protected] wrote:
From: Nicola Vetrini <[email protected]>
Function
reboot_machine' does not return, but lacks thenoreturn' attribute,
therefore causing a violation of MISRA C Rule 2.1: "A project shall not contain
unreachable code".Is this (uniformly) true? Looking at ...
Quoted 11 lines
xen/common/keyhandler.c +1
-1@@ -251,7 +251,7 @@ static void cf_check dump_hwdom_registers(unsigned char key) } } -static void cf_check reboot_machine(unsigned char key, bool unused) +static void noreturn cf_check reboot_machine(unsigned char key, bool unused) {Quoted 2 lines
printk("'%c' pressed -> rebooting machine\n", key); machine_restart(0);... generated code here, I can see that the compiler is perfectly able to
leverage the noreturn thatmachine_restart()has, resulting in no unreachable code to be generated. That is - neither in source nor in binary there is any unreachable code. Therefore I'm having a hard time seeing what the violation is here.That said, I certainly don't mind the addition of the (seemingly) missing
attribute. Otoh I wonder whether an attribute the removal of which has no
effect wouldn't count as "dead code" or alike, violating some other rule.Quoted 6 lines
Quoted 6 lines
Inlining does not play a role in this case. Here
reboot_machine()is marked as a violation becausemachine_restart()is noreturn and there is no other path upon whichreboot_machine()may return, hence any function callingreboot_machine()could have portions that are inadvertently unreachable (as in never executed due to divergence) by not having the annotation.Just that there's not going to be a 2nd caller, considering the purpose of the function.
Quoted 9 lines
Quoted 4 lines
That said, in such trivial cases compilers
are typically able to derive the property automatically, but they are not obliged to and, more importantly, the behavior may even differ with the same compiler using different optimization levels.Just a note: in later revisions of MISRA C this has become a rule of its own [1], which helps reduce confusion, but up to MISRA C:2012 Amendment 2 (currently used by Xen), this is part of Rule 2.1.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
[1] Rule 17.11: "A function that never returns should be declared with a
_Noreturnfunction specifier"Oh, that's indeed quite a bit more explicit.
Does it mean you would ack the patch? :-)
With an improved description I may at least no longer object to it.
Jan