[PATCH v2] arm/efi: address MISRA C Rule 11.3

Dmytro Prokopchuk1 posted 1 patch 1 day, 22 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/212a1ac4ee568f027f6cb7f9437aa42d2f0b6c41.1761599221.git.dmytro._5Fprokopchuk1@epam.com
xen/arch/arm/efi/efi-boot.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH v2] arm/efi: address MISRA C Rule 11.3
Posted by Dmytro Prokopchuk1 1 day, 22 hours ago
MISRA C Rule 11.3 prohibits casting between pointer-to-object types that
are different types. The original code used a macro 'NextMemoryDescriptor()'
that performed a non-compliant cast from 'UINT8*' to 'EFI_MEMORY_DESCRIPTOR*'.

Change 'efi_process_memory_map_bootinfo()' function parameter from
'EFI_MEMORY_DESCRIPTOR *' to 'void *' for the memory map parameter. Replace
usage of 'NextMemoryDescriptor()' macro with compliant pointer arithmetic
on 'void *', followed by a single compliant cast to 'EFI_MEMORY_DESCRIPTOR *'.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Changes in v2:
- removed 'NextMemoryDescriptor()' macro and used pointer arithmetic like in x86

Link to v1:
https://patchew.org/Xen/78112778d6fd5f720f7102db7125c844b747a962.1761242341.git.dmytro._5Fprokopchuk1@epam.com/

Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2123465709
---
 xen/arch/arm/efi/efi-boot.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 7844b9529e..ea59de47e7 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -191,15 +191,16 @@ static bool __init meminfo_add_bank(struct membanks *mem,
     return true;
 }
 
-static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *map,
+static EFI_STATUS __init efi_process_memory_map_bootinfo(void *map,
                                                 UINTN mmap_size,
                                                 UINTN desc_size)
 {
     int Index;
-    EFI_MEMORY_DESCRIPTOR *desc_ptr = map;
 
     for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
     {
+        EFI_MEMORY_DESCRIPTOR *desc_ptr = map + desc_size * Index;
+
         if ( !(desc_ptr->Attribute & EFI_MEMORY_RUNTIME) &&
              (desc_ptr->Attribute & EFI_MEMORY_WB) &&
              (desc_ptr->Type == EfiConventionalMemory ||
@@ -227,7 +228,6 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *
             }
         }
 #endif
-        desc_ptr = NextMemoryDescriptor(desc_ptr, desc_size);
     }
 
     return EFI_SUCCESS;
-- 
2.43.0