From 4cf6c288cd125ec03b62adbab844125c197025ca Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 29 Oct 2021 09:32:14 +0800 Subject: [PATCH] HV: treewide: fix warnings raised by Clang This patch fixes the following warnings detected by the LLVM/Clang compiler: 1. Unused static functions in C sources, which are fixed by explicitly tagging them with __unused 2. Duplicated parentheses around branch conditions 3. Assigning 64-bit constants to 32-bit variables, which is fixed by promoting the variables to uint64_t 4. Using { '\0' } to zero-fill an array, which is fixed by replacing it with { 0 } 5. Taking a bit out of a variable using && (which should be & instead) Most changes do not have a semantic impact, except item 5 which is probably a real code issue. Tracked-On: #6776 Signed-off-by: Junjie Mao Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/instr_emul.c | 7 +++---- hypervisor/arch/x86/guest/ve820.c | 2 +- hypervisor/arch/x86/guest/vlapic.c | 2 +- hypervisor/arch/x86/guest/vm.c | 4 ++-- hypervisor/arch/x86/guest/vmexit.c | 2 +- hypervisor/boot/guest/vboot_info.c | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hypervisor/arch/x86/guest/instr_emul.c b/hypervisor/arch/x86/guest/instr_emul.c index 6d3ee6f59..165127e4e 100644 --- a/hypervisor/arch/x86/guest/instr_emul.c +++ b/hypervisor/arch/x86/guest/instr_emul.c @@ -266,7 +266,7 @@ static inline uint32_t seg_desc_type(uint32_t access) return (access & 0x001fU); } -static inline bool seg_desc_present(uint32_t access) +__unused static inline bool seg_desc_present(uint32_t access) { return ((access & 0x0080U) != 0U); } @@ -276,7 +276,7 @@ static inline bool seg_desc_def32(uint32_t access) return ((access & 0x4000U) != 0U); } -static inline bool seg_desc_unusable(uint32_t access) +__unused static inline bool seg_desc_unusable(uint32_t access) { return ((access & 0x10000U) != 0U); } @@ -439,7 +439,7 @@ static uint32_t get_vmcs_field(enum cpu_reg_name ident) static uint64_t vm_get_register(const struct acrn_vcpu *vcpu, enum cpu_reg_name reg) { uint64_t reg_val = 0UL; - + if ((reg >= CPU_REG_GENERAL_FIRST) && (reg <= CPU_REG_GENERAL_LAST)) { reg_val = vcpu_get_gpreg(vcpu, reg); } else if ((reg >= CPU_REG_NONGENERAL_FIRST) && @@ -2470,4 +2470,3 @@ bool is_current_opcode_xchg(struct acrn_vcpu *vcpu) { return (vcpu->inst_ctxt.vie.op.op_type == VIE_OP_TYPE_XCHG); } - diff --git a/hypervisor/arch/x86/guest/ve820.c b/hypervisor/arch/x86/guest/ve820.c index f95bf5df1..d77a2913c 100644 --- a/hypervisor/arch/x86/guest/ve820.c +++ b/hypervisor/arch/x86/guest/ve820.c @@ -169,7 +169,7 @@ void create_service_vm_e820(struct acrn_vm *vm) for (i = 0U; i < vm->e820_entry_num; i++) { struct e820_entry *entry = &service_vm_e820[i]; - if ((entry->type == E820_TYPE_RAM)) { + if (entry->type == E820_TYPE_RAM) { service_vm_config->memory.size += entry->length; } } diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index 38b9138ce..fad39a33f 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -223,7 +223,7 @@ vlapic_timer_divisor_shift(uint32_t dcr) return ((val + 1U) & 0x7U); } -static inline bool +__unused static inline bool vlapic_lvtt_oneshot(const struct acrn_vlapic *vlapic) { return (((vlapic->apic_page.lvt[APIC_LVT_TIMER].v) & APIC_LVTT_TM) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 5fffd9d48..33393ca4b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -321,9 +321,9 @@ static void prepare_prelaunched_vm_memmap(struct acrn_vm *vm, const struct acrn_ static void deny_pci_bar_access(struct acrn_vm *service_vm, const struct pci_pdev *pdev) { - uint32_t idx, mask; + uint32_t idx; struct pci_vbar vbar = {}; - uint64_t base = 0UL, size = 0UL; + uint64_t base = 0UL, size = 0UL, mask; uint64_t *pml4_page; pml4_page = (uint64_t *)service_vm->arch_vm.nworld_eptp; diff --git a/hypervisor/arch/x86/guest/vmexit.c b/hypervisor/arch/x86/guest/vmexit.c index f973cf4ca..01ec718f4 100644 --- a/hypervisor/arch/x86/guest/vmexit.c +++ b/hypervisor/arch/x86/guest/vmexit.c @@ -396,7 +396,7 @@ static int32_t xsetbv_vmexit_handler(struct acrn_vcpu *vcpu) uint32_t cpl; uint64_t val64; - if (vcpu->arch.xsave_enabled && ((vcpu_get_cr4(vcpu) && CR4_OSXSAVE) != 0UL)) { + if (vcpu->arch.xsave_enabled && ((vcpu_get_cr4(vcpu) & CR4_OSXSAVE) != 0UL)) { idx = vcpu->arch.cur_context; /* get current privilege level */ cpl = exec_vmread32(VMX_GUEST_CS_ATTR); diff --git a/hypervisor/boot/guest/vboot_info.c b/hypervisor/boot/guest/vboot_info.c index cba4a7f84..268ca9816 100644 --- a/hypervisor/boot/guest/vboot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -72,7 +72,7 @@ static int32_t init_vm_kernel_info(struct acrn_vm *vm, const struct abi_module * } /* cmdline parsed from abi module string, for pre-launched VMs and Service VM only. */ -static char mod_cmdline[PRE_VM_NUM + SERVICE_VM_NUM][MAX_BOOTARGS_SIZE] = { '\0' }; +static char mod_cmdline[PRE_VM_NUM + SERVICE_VM_NUM][MAX_BOOTARGS_SIZE] = { 0 }; /** * @pre vm != NULL && abi != NULL