From 7494ed27757c0a295994061b42d161e6af8b4aeb Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Wed, 8 May 2019 20:20:54 +0800 Subject: [PATCH] Clean up MISRA C violation clean up a few MISRA C violations that can be fixed by code change in vboot files Tracked-On: #861 Signed-off-by: Jason Chen CJ --- efi-stub/boot.c | 2 +- hypervisor/boot/guest/deprivilege_boot.c | 10 +++---- hypervisor/boot/guest/vboot_wrapper.c | 27 +++++++++++-------- .../boot/include/guest/deprivilege_boot.h | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/efi-stub/boot.c b/efi-stub/boot.c index 0e805d90a..dccbf5664 100644 --- a/efi-stub/boot.c +++ b/efi-stub/boot.c @@ -271,7 +271,7 @@ switch_to_guest_mode(EFI_HANDLE image, EFI_PHYSICAL_ADDRESS hv_hpa) if (addr < 4096) Print(L"Warning: CPU trampoline code buf occupied zero-page\n"); - efi_ctx->ap_trampoline_buf = (void *)addr; + efi_ctx->ap_trampoline_buf = addr; config_table = sys_table->ConfigurationTable; diff --git a/hypervisor/boot/guest/deprivilege_boot.c b/hypervisor/boot/guest/deprivilege_boot.c index 1ef003b14..88a3ffbac 100644 --- a/hypervisor/boot/guest/deprivilege_boot.c +++ b/hypervisor/boot/guest/deprivilege_boot.c @@ -26,13 +26,13 @@ static void init_depri_boot(void) struct multiboot_info *mbi = NULL; if (!depri_initialized) { - parse_hv_cmdline(); + (void)parse_hv_cmdline(); mbi = (struct multiboot_info *) hpa2hva(((uint64_t)(uint32_t)boot_regs[1])); - if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U) { + if ((mbi == NULL) || ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U)) { pr_err("no multiboot drivers for depri_boot found"); } else { - memcpy_s(&depri_boot_ctx, sizeof(struct depri_boot_context), + (void)memcpy_s(&depri_boot_ctx, sizeof(struct depri_boot_context), hpa2hva((uint64_t)mbi->mi_drives_addr), sizeof(struct depri_boot_context)); save_lapic(&depri_boot_lapic_regs); @@ -55,7 +55,7 @@ const struct lapic_regs *get_depri_boot_lapic_regs(void) static uint64_t get_depri_boot_ap_trampoline(void) { - return (uint64_t)(depri_boot_ctx.ap_trampoline_buf); + return depri_boot_ctx.ap_trampoline_buf; } static void* get_depri_boot_rsdp(void) @@ -63,7 +63,7 @@ static void* get_depri_boot_rsdp(void) return hpa2hva((uint64_t)(depri_boot_ctx.rsdp)); } -static void depri_boot_spurious_handler(int32_t vector) +static void depri_boot_spurious_handler(uint32_t vector) { if (get_pcpu_id() == BOOT_CPU_ID) { struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID); diff --git a/hypervisor/boot/guest/vboot_wrapper.c b/hypervisor/boot/guest/vboot_wrapper.c index 6c711f6bf..297b6fbb6 100644 --- a/hypervisor/boot/guest/vboot_wrapper.c +++ b/hypervisor/boot/guest/vboot_wrapper.c @@ -12,6 +12,7 @@ #include #include #include +#include #define BOOTLOADER_NUM 4U #define BOOTLOADER_NAME_SIZE 20U @@ -42,18 +43,22 @@ void init_vboot_operations(void) }; mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]); - for (i = 0U; i < BOOTLOADER_NUM; i++) { - if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name, - strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) { - /* Only support two vboot mode */ - if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) { - vboot_ops = get_deprivilege_boot_ops(); - sos_boot_mode = DEPRI_BOOT_MODE; - } else { - vboot_ops = get_direct_boot_ops(); - sos_boot_mode = DIRECT_BOOT_MODE; + if (mbi == NULL) { + panic("No multiboot info"); + } else { + for (i = 0U; i < BOOTLOADER_NUM; i++) { + if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name, + strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) { + /* Only support two vboot mode */ + if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) { + vboot_ops = get_deprivilege_boot_ops(); + sos_boot_mode = DEPRI_BOOT_MODE; + } else { + vboot_ops = get_direct_boot_ops(); + sos_boot_mode = DIRECT_BOOT_MODE; + } + break; } - break; } } } diff --git a/hypervisor/boot/include/guest/deprivilege_boot.h b/hypervisor/boot/include/guest/deprivilege_boot.h index fcff5dfc8..1a03a3090 100644 --- a/hypervisor/boot/include/guest/deprivilege_boot.h +++ b/hypervisor/boot/include/guest/deprivilege_boot.h @@ -12,7 +12,7 @@ struct depri_boot_context { struct acrn_vcpu_regs vcpu_regs; void *rsdp; - void *ap_trampoline_buf; + uint64_t ap_trampoline_buf; } __packed; const struct depri_boot_context *get_depri_boot_ctx(void);