diff mbox series

[XEN,v2,2/7] x86/mm: address MISRA C:2012 Rule 2.1

Message ID 1cd82cf19a613a122a770bf6670e681ca7fccd44.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 "return 0" after the swich statement in 'xen/arch/x86/mm.c'
is unreachable because all switch clauses end with returns, and
can thus be dropped.

No functional changes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
Changes in v2:
- Drop the final return instead. A stripped-down version of this switch has been
  tested on godbolt.org with gcc-4.1.2 and shows no compile-time issues.
---
 xen/arch/x86/mm.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Stefano Stabellini Dec. 19, 2023, 1:33 a.m. UTC | #1
On Mon, 18 Dec 2023, Nicola Vetrini wrote:
> The "return 0" after the swich statement in 'xen/arch/x86/mm.c'
> is unreachable because all switch clauses end with returns, and
> can thus be dropped.
> 
> No functional changes.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Jan Beulich Dec. 19, 2023, 10:56 a.m. UTC | #2
On 18.12.2023 11:17, Nicola Vetrini wrote:
> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -4887,8 +4887,6 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>      default:
>          return subarch_memory_op(cmd, arg);
>      }
> -
> -    return 0;
>  }

When a function is small and it's easy to see that all paths return by
other means, omitting such a final "return <value>" is imo okay. Here,
however, this isn't easy to see, and hence omitting the return is
confusing in a different way from having the return. I guess I'll make
an alternative change (as iirc I had outlined before), for other x86
maintainers to at least consider. The other alternative (causing less
code churn) would imo be to pull out the default case from the switch().

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 0a66db10b959..49d9f371f35c 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -4887,8 +4887,6 @@  long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     default:
         return subarch_memory_op(cmd, arg);
     }
-
-    return 0;
 }
 
 int cf_check mmio_ro_emulated_write(