Skip to content

xen: address MISRA C:2012 Rule 2.1

Nicola Vetrini xen-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest11 patches 44 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11x86/efi: move variable declaration to address MISRA C:2012 Rule 2.1xen/arch/x86/efi/efi-boot.h+2 -33 replies
2/11x86: move declarations to address MISRA C:2012 Rule 2.1xen/arch/x86/cpuid.c xen/arch/x86/domain.c xen/arch/x86/irq.c +1 more+14 -1811 replies
3/11x86/uaccess: move declarations to address MISRA C:2012 Rule 2.1xen/arch/x86/include/asm/uaccess.h+4 -21 reply
4/11x86emul: move variable definitions to address MISRA C:2012 Rule 2.1xen/arch/x86/hvm/emulate.c xen/arch/x86/hvm/hvm.c xen/arch/x86/x86_emulate/0f01.c +5 more+31 -362 replies
5/11drivers/pci: move variable definitions to address MISRA C:2012 Rule 2.1xen/drivers/passthrough/pci.c+4 -61 reply
6/11xen/ioreq: move variable declaration to address MISRA C:2012 Rule 2.1xen/common/ioreq.c+1 -20 replies
7/11xen: address MISRA C:2012 Rule 2.1xen/common/shutdown.c+12 -612 replies
8/11xen: move declarations to address MISRA C:2012 Rule 2.1xen/common/compat/memory.c xen/common/domain.c+8 -100 replies
9/11x86/xstate: moved BUILD_BUG_ON to address MISRA C:2012 Rule 2.1xen/arch/x86/xstate.c+2 -10 replies
10/11xen/sched: add ASSERT_UNREACHABLE() to address MISRA C:2012 Rule 2.1xen/common/sched/core.c+1 -011 replies
11/11x86/mm: Add assertion to address MISRA C:2012 Rule 2.1xen/arch/x86/mm.c xen/arch/x86/mm/p2m-pod.c+2 -03 replies

Reviews trailers per patch

1 of 11 patches has a Reviewed-by or Acked-by.

PatchStefano Stabellini
1/11
2/11
3/11R-b
4/11
5/11
6/11
7/11
8/11
9/11
10/11
11/11

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [XEN PATCH 00/11] xen: address MISRA C:2012 Rule 2.1

The headline for Rule 2.1 states:
"A project shall not contain unreachable code". Violations of this rule addressed by this patch are caused by two constructs:

1. Declarations inside switch statements, before any clause. This construct is allowed by the language, but is considered unreachable code, since the program execution doesn't ever reach these statements, even though the variables are introduced in the switch block.
2. Code following functions that are not intended to return to the caller or additional statements required by defensive programming practices or other MISRA rules (such as a break to end each switch clause, even if that break is effectively unreachable).

(1) is resolved by moving the declarations in an appropriate scope, while (2) is addressed by adding ASSERT_UNREACHABLE() calls to signal that the code below is intentionally unreachable, thus motivating the violation of the rule.

---
The approach taken in this series to address the violations is the outcome of a MISRA C group meeting held 25/07/2023.

Nicola Vetrini (11):
x86/efi: move variable declaration to address MISRA C:2012 Rule 2.1
x86: move declarations to address MISRA C:2012 Rule 2.1 x86/uaccess: move declarations to address MISRA C:2012 Rule 2.1
x86emul: move variable definitions to address MISRA C:2012 Rule 2.1 drivers/pci: move variable definitions to address MISRA C:2012 Rule

    2.1

xen/ioreq: move variable declaration to address MISRA C:2012 Rule 2.1
xen: address MISRA C:2012 Rule 2.1
xen: move declarations to address MISRA C:2012 Rule 2.1 x86/xstate: moved BUILD_BUG_ON to address MISRA C:2012 Rule 2.1 xen/sched: add ASSERT_UNREACHABLE() to address MISRA C:2012 Rule 2.1 x86/mm: Add assertion to address MISRA C:2012 Rule 2.1

 xen/arch/x86/cpuid.c                   |  3 +--
 xen/arch/x86/domain.c                  | 23 +++++++++++------------
 xen/arch/x86/efi/efi-boot.h            |  5 ++---
 xen/arch/x86/hvm/emulate.c             |  9 ++++-----
 xen/arch/x86/hvm/hvm.c                 | 10 ++++------
 xen/arch/x86/include/asm/uaccess.h     |  6 ++++--
 xen/arch/x86/irq.c                     |  3 +--
 xen/arch/x86/mm.c                      |  1 +
 xen/arch/x86/mm/p2m-pod.c              |  1 +
 xen/arch/x86/msr.c                     |  3 +--
 xen/arch/x86/x86_emulate/0f01.c        |  7 +++----
 xen/arch/x86/x86_emulate/blk.c         | 17 ++++++++---------
 xen/arch/x86/x86_emulate/decode.c      |  3 ++-
 xen/arch/x86/x86_emulate/fpu.c         |  3 +--
 xen/arch/x86/x86_emulate/util-xen.c    |  4 ++--
 xen/arch/x86/x86_emulate/x86_emulate.c | 14 +++++++-------
 xen/arch/x86/xstate.c                  |  3 ++-
 xen/common/compat/memory.c             |  3 +--
 xen/common/domain.c                    | 15 +++++++--------
 xen/common/ioreq.c                     |  3 +--
 xen/common/sched/core.c                |  1 +
 xen/common/shutdown.c                  | 18 ++++++++++++------
 xen/drivers/passthrough/pci.c          | 10 ++++------
 23 files changed, 81 insertions(+), 84 deletions(-)

--
2.34.1