From 714162fb8b721ad8823fbaea3d27bcc9aee25513 Mon Sep 17 00:00:00 2001 From: Huihuang Shi Date: Tue, 9 Jul 2019 15:40:13 +0800 Subject: [PATCH] HV: fix violations touched type conversion ACRN Coding guidelines requires type conversion shall be explicity. Tracked-On: #861 Signed-off-by: Huihuang Shi Acked-by: Eddie Dong --- hypervisor/arch/x86/configs/vmptable.c | 8 ++++---- hypervisor/arch/x86/guest/trusty.c | 4 ++-- hypervisor/arch/x86/guest/vcpuid.c | 4 ++-- hypervisor/arch/x86/ioapic.c | 2 +- hypervisor/arch/x86/seed/seed.c | 2 +- hypervisor/boot/cmdline.c | 2 +- hypervisor/boot/guest/vboot_info.c | 2 +- hypervisor/debug/console.c | 5 +++-- hypervisor/debug/profiling.c | 2 +- hypervisor/debug/shell.c | 4 ++-- hypervisor/dm/vrtc.c | 2 +- hypervisor/include/arch/x86/apicreg.h | 4 ++-- hypervisor/include/dm/mptable.h | 10 +++++----- 13 files changed, 26 insertions(+), 25 deletions(-) diff --git a/hypervisor/arch/x86/configs/vmptable.c b/hypervisor/arch/x86/configs/vmptable.c index 2fa023167..94becd2e4 100644 --- a/hypervisor/arch/x86/configs/vmptable.c +++ b/hypervisor/arch/x86/configs/vmptable.c @@ -105,10 +105,10 @@ int32_t mptable_build(struct acrn_vm *vm) (const void *)&mptable_template, sizeof(struct mptable_info)); mptable->mpch.entry_count = vcpu_num + MPE_NUM_BUSES + MPEII_NUM_LOCAL_IRQ; - mptable->mpch.base_table_length = sizeof(struct mpcth) - + vcpu_num * sizeof(struct proc_entry) - + MPE_NUM_BUSES * sizeof(struct bus_entry) - + MPEII_NUM_LOCAL_IRQ * sizeof(struct int_entry); + mptable->mpch.base_table_length = (uint16_t)sizeof(struct mpcth) + + vcpu_num * (uint16_t)sizeof(struct proc_entry) + + MPE_NUM_BUSES * (uint16_t)sizeof(struct bus_entry) + + MPEII_NUM_LOCAL_IRQ * (uint16_t)sizeof(struct int_entry); mptable_length = sizeof(struct mpfps) + mptable->mpch.base_table_length; if (mptable_length <= MPTABLE_MAX_LENGTH) { diff --git a/hypervisor/arch/x86/guest/trusty.c b/hypervisor/arch/x86/guest/trusty.c index b3ed09967..f2cbc1f71 100644 --- a/hypervisor/arch/x86/guest/trusty.c +++ b/hypervisor/arch/x86/guest/trusty.c @@ -349,9 +349,9 @@ static bool setup_trusty_info(struct acrn_vcpu *vcpu, uint32_t mem_size, uint64_ stac(); mem = (struct trusty_mem *)(hpa2hva(mem_base_hpa)); - (void)memcpy_s(&mem->first_page.key_info, sizeof(struct trusty_key_info), + (void)memcpy_s((void *)&mem->first_page.key_info, sizeof(struct trusty_key_info), &key_info, sizeof(key_info)); - (void)memcpy_s(&mem->first_page.startup_param, sizeof(struct trusty_startup_param), + (void)memcpy_s((void *)&mem->first_page.startup_param, sizeof(struct trusty_startup_param), &startup_param, sizeof(startup_param)); clac(); success = true; diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index 8d0c7b99b..0a9590135 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -210,8 +210,8 @@ static int32_t set_vcpuid_sgx(struct acrn_vm *vm) if (result == 0) { init_vcpuid_entry(CPUID_SGX_LEAF, 1U, CPUID_CHECK_SUBLEAF, &entry); /* MPX not present to guest */ - entry.ecx &= ~XCR0_BNDREGS; - entry.ecx &= ~XCR0_BNDCSR; + entry.ecx &= (uint32_t) ~XCR0_BNDREGS; + entry.ecx &= (uint32_t) ~XCR0_BNDCSR; result = set_vcpuid_entry(vm, &entry); } if (result == 0) { diff --git a/hypervisor/arch/x86/ioapic.c b/hypervisor/arch/x86/ioapic.c index 28d1f1117..0167652ca 100644 --- a/hypervisor/arch/x86/ioapic.c +++ b/hypervisor/arch/x86/ioapic.c @@ -225,7 +225,7 @@ create_rte_for_gsi_irq(uint32_t irq, uint32_t vr) rte.bits.intr_polarity = IOAPIC_RTE_INTPOL_AHI; /* Dest field */ - rte.bits.dest_field = ALL_CPUS_MASK; + rte.bits.dest_field = (uint8_t) ALL_CPUS_MASK; } return rte; diff --git a/hypervisor/arch/x86/seed/seed.c b/hypervisor/arch/x86/seed/seed.c index bc3cff5d7..05c6e57fd 100644 --- a/hypervisor/arch/x86/seed/seed.c +++ b/hypervisor/arch/x86/seed/seed.c @@ -71,7 +71,7 @@ static uint32_t parse_seed_arg(void) arg -= len; len = (arg_end != NULL) ? (uint32_t)(arg_end - arg) : strnlen_s(arg, MAX_BOOTARGS_SIZE); - (void)memset((void *)arg, (char)' ', len); + (void)memset((void *)arg, (uint8_t)' ', len); break; } } diff --git a/hypervisor/boot/cmdline.c b/hypervisor/boot/cmdline.c index 0353dd6f3..cb8500b07 100644 --- a/hypervisor/boot/cmdline.c +++ b/hypervisor/boot/cmdline.c @@ -43,7 +43,7 @@ int32_t parse_hv_cmdline(void) while ((*end != ' ') && ((*end) != '\0')) end++; - if (!handle_dbg_cmd(start, end - start)) { + if (!handle_dbg_cmd(start, (int32_t)(end - start))) { /* if not handled by handle_dbg_cmd, it can be handled further */ } start = end + 1; diff --git a/hypervisor/boot/guest/vboot_info.c b/hypervisor/boot/guest/vboot_info.c index 61e5315b0..77ba24b1f 100644 --- a/hypervisor/boot/guest/vboot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -299,7 +299,7 @@ static int32_t depri_boot_sw_loader(struct acrn_vm *vm) * We copy the info saved in depri_boot to boot_context and * init bsp with boot_context. */ - (void)memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs), + (void)memcpy_s((void *)&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs), &(depri_boot_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs)); vcpu_regs->rip = depri_boot_ctx->vcpu_regs.rip; diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 28e529c0e..caceedadd 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -79,10 +79,11 @@ static void vuart_console_rx_chars(struct acrn_vuart *vu) */ static void vuart_console_tx_chars(struct acrn_vuart *vu) { - char c; + char c = vuart_getchar(vu); - while ((c = vuart_getchar(vu)) != -1) { + while(c != -1) { printf("%c", c); + c = vuart_getchar(vu); } } diff --git a/hypervisor/debug/profiling.c b/hypervisor/debug/profiling.c index 40631757a..cf12146cf 100644 --- a/hypervisor/debug/profiling.c +++ b/hypervisor/debug/profiling.c @@ -1382,7 +1382,7 @@ void profiling_pre_vmexit_handler(struct acrn_vcpu *vcpu) get_cpu_var(profiling_info.vm_info).guest_cs = exec_vmread64(VMX_GUEST_CS_SEL); - get_cpu_var(profiling_info.vm_info).guest_vm_id = (int32_t)vcpu->vm->vm_id; + get_cpu_var(profiling_info.vm_info).guest_vm_id = (int16_t)vcpu->vm->vm_id; } } diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index a5912008b..65350f5fa 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -876,8 +876,8 @@ static int32_t shell_to_vm_console(int32_t argc, char **argv) struct acrn_vm *vm; struct acrn_vuart *vu; - if (argc == 2U) { - vm_id = sanitize_vmid(strtol_deci(argv[1])); + if (argc == 2) { + vm_id = sanitize_vmid((uint16_t)strtol_deci(argv[1])); } /* Get the virtual device node */ diff --git a/hypervisor/dm/vrtc.c b/hypervisor/dm/vrtc.c index 6adf05359..6f9bcc230 100644 --- a/hypervisor/dm/vrtc.c +++ b/hypervisor/dm/vrtc.c @@ -29,7 +29,7 @@ static bool cmos_update_in_progress(void) static uint8_t cmos_get_reg_val(uint8_t addr) { uint8_t reg; - int32_t tries = 2000U; + int32_t tries = 2000; spinlock_obtain(&cmos_lock); diff --git a/hypervisor/include/arch/x86/apicreg.h b/hypervisor/include/arch/x86/apicreg.h index 3e5918dd4..d3afc3e58 100644 --- a/hypervisor/include/arch/x86/apicreg.h +++ b/hypervisor/include/arch/x86/apicreg.h @@ -198,7 +198,7 @@ union ioapic_rte { uint32_t hi_32; } u; struct { - uint64_t vector:8; + uint8_t vector:8; uint64_t delivery_mode:3; uint64_t dest_mode:1; uint64_t delivery_status:1; @@ -207,7 +207,7 @@ union ioapic_rte { uint64_t trigger_mode:1; uint64_t intr_mask:1; uint64_t rsvd_1:39; - uint64_t dest_field:8; + uint8_t dest_field:8; } bits __packed; struct { uint32_t vector:8; diff --git a/hypervisor/include/dm/mptable.h b/hypervisor/include/dm/mptable.h index 82ca367b0..dd189da06 100644 --- a/hypervisor/include/dm/mptable.h +++ b/hypervisor/include/dm/mptable.h @@ -82,7 +82,7 @@ /* MP Floating Pointer Structure */ struct mpfps { - uint8_t signature[4]; + char signature[4]; uint32_t pap; uint8_t length; uint8_t spec_rev; @@ -96,12 +96,12 @@ struct mpfps { /* MP Configuration Table Header */ struct mpcth { - uint8_t signature[4]; + char signature[4]; uint16_t base_table_length; uint8_t spec_rev; uint8_t checksum; - uint8_t oem_id[8]; - uint8_t product_id[12]; + char oem_id[8]; + char product_id[12]; uint32_t oem_table_pointer; uint16_t oem_table_size; uint16_t entry_count; @@ -125,7 +125,7 @@ struct proc_entry { struct bus_entry { uint8_t type; uint8_t bus_id; - uint8_t bus_type[6]; + char bus_type[6]; } __packed; struct int_entry {