diff mbox series

[XEN,v2,3/7] xen/arm: address MISRA C:2012 Rule 2.1

Message ID 06857c133d1db8ab3a2eec5e0363be4358a0ec81.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
There are no paths that can reach the last return statement
of function 'vgic_v3_its_mmio_write' in 'vcig-v3-its.c' and
'arch_memory_op' in 'arch/arm/mm.c', thus violating
MISRA C:2012 Rule 2.1:
"A project shall not contain unreachable code".

Therefore, an ASSERT_UNREACHABLE() is inserted to remove the unreachable
return statement and protect against possible mistakes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
Changes in v2:
- Changed resolution strategy to have an ASSERT_UNREACHABLE() before
  the return.
---
 xen/arch/arm/mm.c          | 1 +
 xen/arch/arm/vgic-v3-its.c | 1 +
 2 files changed, 2 insertions(+)

Comments

Stefano Stabellini Dec. 19, 2023, 1:35 a.m. UTC | #1
On Mon, 18 Dec 2023, Nicola Vetrini wrote:

> There are no paths that can reach the last return statement
> of function 'vgic_v3_its_mmio_write' in 'vcig-v3-its.c' and
> 'arch_memory_op' in 'arch/arm/mm.c', thus violating
> MISRA C:2012 Rule 2.1:
> "A project shall not contain unreachable code".
> 
> Therefore, an ASSERT_UNREACHABLE() is inserted to remove the unreachable
> return statement and protect against possible mistakes.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

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


> ---
> Changes in v2:
> - Changed resolution strategy to have an ASSERT_UNREACHABLE() before
>   the return.
> ---
>  xen/arch/arm/mm.c          | 1 +
>  xen/arch/arm/vgic-v3-its.c | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index eeb65ca6bb79..b15a18a49412 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -283,6 +283,7 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
>          return -ENOSYS;
>      }
>  
> +    ASSERT_UNREACHABLE();
>      return 0;
>  }
>  
> diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c
> index 05429030b539..70b5aeb82219 100644
> --- a/xen/arch/arm/vgic-v3-its.c
> +++ b/xen/arch/arm/vgic-v3-its.c
> @@ -1409,6 +1409,7 @@ static int vgic_v3_its_mmio_write(struct vcpu *v, mmio_info_t *info,
>          return 0;
>      }
>  
> +    ASSERT_UNREACHABLE();
>      return 1;
>  
>  write_ignore_64:
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index eeb65ca6bb79..b15a18a49412 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -283,6 +283,7 @@  long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
+    ASSERT_UNREACHABLE();
     return 0;
 }
 
diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c
index 05429030b539..70b5aeb82219 100644
--- a/xen/arch/arm/vgic-v3-its.c
+++ b/xen/arch/arm/vgic-v3-its.c
@@ -1409,6 +1409,7 @@  static int vgic_v3_its_mmio_write(struct vcpu *v, mmio_info_t *info,
         return 0;
     }
 
+    ASSERT_UNREACHABLE();
     return 1;
 
 write_ignore_64: