diff mbox series

[XEN,v2,4/7] xen/arm: traps: add ASSERT_UNREACHABLE() where needed

Message ID 02070d1bb4bfc0e88d548a529bef8bedab5b3488.1702891792.git.nicola.vetrini@bugseng.com (mailing list archive)
State New, archived
Headers show
Series address violations of MISRA C:2012 Rule 2.1 | expand

Commit Message

Nicola Vetrini Dec. 18, 2023, 10:17 a.m. UTC
The statements after a call to the noreturn function 'do_unexpected_trap'
can't be reached, thus violating MISRA C:2012 Rule 2.1
("A project shall not contain unreachable code.").
ASSERT_UNREACHABLE() is used to signal that the unreachable break-s are used as
a defensive coding measure to prevent inadvertent fallthrough.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
Changes in v2:
- Use ASSERT_UNREACHABLE() to prevent mistakes.
---
 xen/arch/arm/traps.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stefano Stabellini Dec. 19, 2023, 1:36 a.m. UTC | #1
On Mon, 18 Dec 2023, Nicola Vetrini wrote:
> The statements after a call to the noreturn function 'do_unexpected_trap'
> can't be reached, thus violating MISRA C:2012 Rule 2.1
> ("A project shall not contain unreachable code.").
> ASSERT_UNREACHABLE() is used to signal that the unreachable break-s are used as
> a defensive coding measure to prevent inadvertent fallthrough.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> Changes in v2:
> - Use ASSERT_UNREACHABLE() to prevent mistakes.
> ---
>  xen/arch/arm/traps.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
> index 3784e8276ef6..77220ba0927a 100644
> --- a/xen/arch/arm/traps.c
> +++ b/xen/arch/arm/traps.c
> @@ -2152,6 +2152,7 @@ void do_trap_hyp_sync(struct cpu_user_regs *regs)
>      case HSR_EC_SVE:
>          /* An SVE exception is a bug somewhere in hypervisor code */
>          do_unexpected_trap("SVE trap at EL2", regs);
> +        ASSERT_UNREACHABLE();
>          break;
>  #endif
>      case HSR_EC_DATA_ABORT_CURR_EL:
> @@ -2171,7 +2172,7 @@ void do_trap_hyp_sync(struct cpu_user_regs *regs)
>              dump_hyp_walk(get_hfar(is_data));
>  
>          do_unexpected_trap(fault, regs);
> -
> +        ASSERT_UNREACHABLE();
>          break;
>      }
>      default:
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 3784e8276ef6..77220ba0927a 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -2152,6 +2152,7 @@  void do_trap_hyp_sync(struct cpu_user_regs *regs)
     case HSR_EC_SVE:
         /* An SVE exception is a bug somewhere in hypervisor code */
         do_unexpected_trap("SVE trap at EL2", regs);
+        ASSERT_UNREACHABLE();
         break;
 #endif
     case HSR_EC_DATA_ABORT_CURR_EL:
@@ -2171,7 +2172,7 @@  void do_trap_hyp_sync(struct cpu_user_regs *regs)
             dump_hyp_walk(get_hfar(is_data));
 
         do_unexpected_trap(fault, regs);
-
+        ASSERT_UNREACHABLE();
         break;
     }
     default: