[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end



On 2024-04-30 13:09, Luca Fancellu wrote:
Commit 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory
bank structures") introduced a MISRA regression for Rule 1.1 because a
flexible array member is introduced in the middle of a struct, furthermore this is using a GCC extension that is going to be deprecated in GCC 14 and
a warning to identify such cases will be present
(-Wflex-array-member-not-at-end) to identify such cases.

In order to fix this issue, use the macro __struct_group to create a
structure 'struct membanks_hdr' which will hold the common data among
structures using the 'struct membanks' interface.

Modify the 'struct shared_meminfo' and 'struct meminfo' to use this new
structure, effectively removing the flexible array member from the middle
of the structure and modify the code accessing the .common field to use
the macro container_of to maintain the functionality of the interface.

Given this change, container_of needs to be supplied with a type and so
the macro 'kernel_info_get_mem' inside arm/include/asm/kernel.h can't be an option since it uses const and non-const types for struct membanks, so introduce two static inline, one of which will keep the const qualifier.

Given the complexity of the interface, which carries a lot of benefit but on the other hand could be prone to developer confusion if the access is
open-coded, introduce two static inline helper for the
'struct kernel_info' .shm_mem member and get rid the open-coding
shm_mem.common access.

Fixes: 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory bank structures")
Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
---
 xen/arch/arm/acpi/domain_build.c        |  2 +-
 xen/arch/arm/domain_build.c             |  6 +++---
 xen/arch/arm/include/asm/kernel.h       | 11 ++++++++++-
 xen/arch/arm/include/asm/setup.h        | 18 ++++++++++--------
 xen/arch/arm/include/asm/static-shmem.h | 12 ++++++++++++
 xen/arch/arm/static-shmem.c             | 19 +++++++++----------
 6 files changed, 45 insertions(+), 23 deletions(-)


From a MISRA perspective the regression on R1.1 is resolved (see [1]).

[1] https://gitlab.com/xen-project/patchew/xen/-/jobs/6748211368

--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.