From be0f5e6c160e1276b28668b541e118f04b73d6c2 Mon Sep 17 00:00:00 2001 From: Huihuang Shi Date: Wed, 20 Jun 2018 13:28:25 +0800 Subject: [PATCH] HV:treewide:fix "expression is not Boolean" MISRA C explicit required expression should be boolean when in branch statements (if,while...). Signed-off-by: Huihuang Shi Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 4 +- hypervisor/arch/x86/guest/vmsr.c | 4 +- hypervisor/arch/x86/intr_lapic.c | 4 +- hypervisor/arch/x86/notify.c | 2 +- hypervisor/arch/x86/softirq.c | 2 +- hypervisor/arch/x86/timer.c | 12 ++--- hypervisor/arch/x86/trusty.c | 8 ++-- hypervisor/arch/x86/vmexit.c | 10 ++--- hypervisor/arch/x86/vmx.c | 46 +++++++++---------- hypervisor/arch/x86/vtd.c | 76 ++++++++++++++++---------------- hypervisor/boot/acpi.c | 12 ++--- hypervisor/boot/sbl/multiboot.c | 14 +++--- hypervisor/bsp/uefi/efi/boot.c | 4 +- hypervisor/bsp/uefi/uefi.c | 4 +- hypervisor/lib/memory.c | 16 +++---- hypervisor/lib/sprintf.c | 58 ++++++++++++------------ hypervisor/lib/string.c | 38 ++++++++-------- 17 files changed, 157 insertions(+), 157 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 35f4655b6..0f7671719 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -224,12 +224,12 @@ int shutdown_vm(struct vm *vm) free_io_emulation_resource(vm); /* Free iommu_domain */ - if (vm->iommu_domain) + if (vm->iommu_domain != NULL) destroy_iommu_domain(vm->iommu_domain); bitmap_clear(vm->attr.id, &vmid_bitmap); - if (vm->vpic) + if (vm->vpic != NULL) vpic_cleanup(vm); free(vm->hw.vcpu_array); diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index 4e42735d1..30276ca57 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -90,7 +90,7 @@ void init_msr_emulation(struct vcpu *vcpu) /* Allocate and initialize memory for MSR bitmap region*/ vcpu->vm->arch_vm.msr_bitmap = alloc_page(); - ASSERT(vcpu->vm->arch_vm.msr_bitmap, ""); + ASSERT(vcpu->vm->arch_vm.msr_bitmap != NULL, ""); memset(vcpu->vm->arch_vm.msr_bitmap, 0x0, CPU_PAGE_SIZE); msr_bitmap = vcpu->vm->arch_vm.msr_bitmap; @@ -307,7 +307,7 @@ int wrmsr_vmexit_handler(struct vcpu *vcpu) } case MSR_IA32_PERF_CTL: { - if (validate_pstate(vcpu->vm, v)) { + if (validate_pstate(vcpu->vm, v) != 0) { break; } msr_write(msr, v); diff --git a/hypervisor/arch/x86/intr_lapic.c b/hypervisor/arch/x86/intr_lapic.c index 525ed9cdb..176e8cc04 100644 --- a/hypervisor/arch/x86/intr_lapic.c +++ b/hypervisor/arch/x86/intr_lapic.c @@ -164,7 +164,7 @@ static void clear_lapic_isr(void) * life, therefore we will ensure all the in-service bits are clear. */ do { - if (read_lapic_reg32(isr_reg)) { + if (read_lapic_reg32(isr_reg) != 0U) { write_lapic_reg32(LAPIC_EOI_REGISTER, 0); continue; } @@ -328,7 +328,7 @@ static void wait_for_delivery(void) do { tmp.value_32.lo_32 = read_lapic_reg32(LAPIC_INT_COMMAND_REGISTER_0); - } while (tmp.bits.delivery_status); + } while (tmp.bits.delivery_status != 0U); } uint32_t get_cur_lapic_id(void) diff --git a/hypervisor/arch/x86/notify.c b/hypervisor/arch/x86/notify.c index 63712c831..f5d0b14e7 100644 --- a/hypervisor/arch/x86/notify.c +++ b/hypervisor/arch/x86/notify.c @@ -63,7 +63,7 @@ void setup_notification(void) void cleanup_notification(void) { - if (notification_node) + if (notification_node != NULL) unregister_handler_common(notification_node); notification_node = NULL; } diff --git a/hypervisor/arch/x86/softirq.c b/hypervisor/arch/x86/softirq.c index 31c4f0cce..1b04a2a0a 100644 --- a/hypervisor/arch/x86/softirq.c +++ b/hypervisor/arch/x86/softirq.c @@ -81,7 +81,7 @@ again: CPU_IRQ_DISABLE(); - if (((*bitmap) & SOFTIRQ_MASK)) + if (((*bitmap) & SOFTIRQ_MASK) != 0U) goto again; enable_softirq(cpu_id); diff --git a/hypervisor/arch/x86/timer.c b/hypervisor/arch/x86/timer.c index df36d9980..76265778e 100644 --- a/hypervisor/arch/x86/timer.c +++ b/hypervisor/arch/x86/timer.c @@ -16,7 +16,7 @@ uint64_t tsc_hz = 1000000000; static void run_timer(struct timer *timer) { /* deadline = 0 means stop timer, we should skip */ - if (timer->func && timer->fire_tsc != 0UL) + if ((timer->func != NULL) && timer->fire_tsc != 0UL) timer->func(timer->priv_data); TRACE_2L(TRACE_TIMER_ACTION_PCKUP, timer->fire_tsc, 0); @@ -62,7 +62,7 @@ static void __add_timer(struct per_cpu_timers *cpu_timer, list_add(&timer->node, prev); - if (need_update) + if (need_update != NULL) /* update the physical timer if we're on the timer_list head */ *need_update = (prev == &cpu_timer->timer_list); } @@ -95,7 +95,7 @@ int add_timer(struct timer *timer) void del_timer(struct timer *timer) { - if (timer && !list_empty(&timer->node)) + if ((timer != NULL) && !list_empty(&timer->node)) list_del_init(&timer->node); } @@ -108,7 +108,7 @@ static int request_timer_irq(int pcpu_id, if (pcpu_id >= phy_cpu_num) return -EINVAL; - if (per_cpu(timer_node, pcpu_id)) { + if (per_cpu(timer_node, pcpu_id) != NULL) { pr_err("CPU%d timer isr already added", pcpu_id); unregister_handler_common(per_cpu(timer_node, pcpu_id)); } @@ -165,7 +165,7 @@ void timer_cleanup(void) { int pcpu_id = get_cpu_id(); - if (per_cpu(timer_node, pcpu_id)) + if (per_cpu(timer_node, pcpu_id) != NULL) unregister_handler_common(per_cpu(timer_node, pcpu_id)); per_cpu(timer_node, pcpu_id) = NULL; @@ -286,7 +286,7 @@ static uint64_t native_calibrate_tsc(void) void calibrate_tsc(void) { tsc_hz = native_calibrate_tsc(); - if (!tsc_hz) + if (tsc_hz == 0U) tsc_hz = pit_calibrate_tsc(CAL_MS); printf("%s, tsc_hz=%lu\n", __func__, tsc_hz); } diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index 3055fc130..742d0b20a 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -315,12 +315,12 @@ static bool setup_trusty_info(struct vcpu *vcpu, /* Derive dvseed from dseed for Trusty */ key_info = &mem->first_page.data.key_info; for (i = 0; i < g_key_info.num_seeds; i++) { - if (!hkdf_sha256(key_info->dseed_list[i].seed, + if (hkdf_sha256(key_info->dseed_list[i].seed, BUP_MKHI_BOOTLOADER_SEED_LEN, g_key_info.dseed_list[i].seed, BUP_MKHI_BOOTLOADER_SEED_LEN, NULL, 0, - vcpu->vm->GUID, sizeof(vcpu->vm->GUID))) { + vcpu->vm->GUID, sizeof(vcpu->vm->GUID)) == 0) { memset(key_info, 0, sizeof(struct key_info)); pr_err("%s: derive dvseed failed!", __func__); return false; @@ -402,12 +402,12 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param) return false; } - if (!boot_param->entry_point) { + if (boot_param->entry_point == 0) { pr_err("%s: Invalid entry point\n", __func__); return false; } - if (!boot_param->base_addr) { + if (boot_param->base_addr == 0) { pr_err("%s: Invalid memory base address\n", __func__); return false; } diff --git a/hypervisor/arch/x86/vmexit.c b/hypervisor/arch/x86/vmexit.c index 0de64f2c8..68286e58c 100644 --- a/hypervisor/arch/x86/vmexit.c +++ b/hypervisor/arch/x86/vmexit.c @@ -143,14 +143,14 @@ int vmexit_handler(struct vcpu *vcpu) vcpu->arch_vcpu.idt_vectoring_info = exec_vmread(VMX_IDT_VEC_INFO_FIELD); /* Filter out HW exception & NMI */ - if (vcpu->arch_vcpu.idt_vectoring_info & VMX_INT_INFO_VALID) { + if ((vcpu->arch_vcpu.idt_vectoring_info & VMX_INT_INFO_VALID) != 0U) { uint32_t vector_info = vcpu->arch_vcpu.idt_vectoring_info; uint32_t vector = vector_info & 0xff; uint32_t type = (vector_info & VMX_INT_TYPE_MASK) >> 8; uint32_t err_code = 0; if (type == VMX_INT_TYPE_HW_EXP) { - if (vector_info & VMX_INT_INFO_ERR_CODE_VALID) + if ((vector_info & VMX_INT_INFO_ERR_CODE_VALID) != 0U) err_code = exec_vmread(VMX_IDT_VEC_ERROR_CODE); vcpu_queue_exception(vcpu, vector, err_code); vcpu->arch_vcpu.idt_vectoring_info = 0; @@ -180,7 +180,7 @@ int vmexit_handler(struct vcpu *vcpu) /* See if an exit qualification is necessary for this exit * handler */ - if (dispatch->need_exit_qualification) { + if (dispatch->need_exit_qualification != 0U) { /* Get exit qualification */ vcpu->arch_vcpu.exit_qualification = exec_vmread(VMX_EXIT_QUALIFICATION); @@ -306,7 +306,7 @@ static int xsetbv_vmexit_handler(struct vcpu *vcpu) struct run_context *ctx_ptr; val64 = exec_vmread(VMX_GUEST_CR4); - if (!(val64 & CR4_OSXSAVE)) { + if ((val64 & CR4_OSXSAVE) == 0U) { vcpu_inject_gp(vcpu, 0); return -1; } @@ -327,7 +327,7 @@ static int xsetbv_vmexit_handler(struct vcpu *vcpu) (ctx_ptr->guest_cpu_regs.regs.rdx << 32); /*bit 0(x87 state) of XCR0 can't be cleared*/ - if (!(val64 & 0x01)) { + if ((val64 & 0x01) == 0U) { vcpu_inject_gp(vcpu, 0); return -1; } diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 5bc9481c8..e863e75a7 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -47,9 +47,9 @@ static inline int exec_vmxon(void *addr) tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL); /* Determine if feature control is locked */ - if (tmp64 & MSR_IA32_FEATURE_CONTROL_LOCK) { + if ((tmp64 & MSR_IA32_FEATURE_CONTROL_LOCK) != 0U) { /* See if VMX enabled */ - if (!(tmp64 & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX)) { + if ((tmp64 & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX) == 0U) { /* Return error - VMX can't be enabled */ pr_err("%s, VMX can't be enabled\n", __func__); status = -EINVAL; @@ -72,7 +72,7 @@ static inline int exec_vmxon(void *addr) : "%rax", "cc", "memory"); /* if carry and zero flags are clear operation success */ - if (rflags & (RFLAGS_C | RFLAGS_Z)) { + if ((rflags & (RFLAGS_C | RFLAGS_Z)) != 0U) { pr_err("%s, Turn VMX on failed\n", __func__); status = -EINVAL; } @@ -117,7 +117,7 @@ int exec_vmxon_instr(uint32_t pcpu_id) per_cpu(vmxon_region_pa, pcpu_id) = HVA2HPA(vmxon_region_va); ret = exec_vmxon(&per_cpu(vmxon_region_pa, pcpu_id)); - if (vcpu) { + if (vcpu != NULL) { vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); ret = exec_vmptrld(&vmcs_pa); } @@ -135,10 +135,10 @@ int vmx_off(int pcpu_id) struct vcpu *vcpu = get_ever_run_vcpu(pcpu_id); uint64_t vmcs_pa; - if (vcpu) { + if (vcpu != NULL) { vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); ret = exec_vmclear((void *)&vmcs_pa); - if (ret) + if (ret != 0) return ret; } @@ -165,7 +165,7 @@ int exec_vmclear(void *addr) : "%rax", "cc", "memory"); /* if carry and zero flags are clear operation success */ - if (rflags & (RFLAGS_C | RFLAGS_Z)) + if ((rflags & (RFLAGS_C | RFLAGS_Z)) != 0U) status = -EINVAL; return status; @@ -190,7 +190,7 @@ int exec_vmptrld(void *addr) : "%rax", "cc"); /* if carry and zero flags are clear operation success */ - if (rflags & (RFLAGS_C | RFLAGS_Z)) + if ((rflags & (RFLAGS_C | RFLAGS_Z)) != 0U) status = -EINVAL; return status; @@ -331,7 +331,7 @@ int vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0) uint32_t entry_ctrls; bool paging_enabled = !!(context->cr0 & CR0_PG); - if (cr0 & (cr0_always_off_mask | CR0_RESERVED_MASK)) { + if ((cr0 & (cr0_always_off_mask | CR0_RESERVED_MASK)) != 0U) { pr_err("Not allow to set always off / reserved bits for CR0"); vcpu_inject_gp(vcpu, 0); return -EINVAL; @@ -340,9 +340,9 @@ int vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0) /* TODO: Check all invalid guest statuses according to the change of * CR0, and inject a #GP to guest */ - if ((context->ia32_efer & MSR_IA32_EFER_LME_BIT) && - !paging_enabled && (cr0 & CR0_PG)) { - if (!(context->cr4 & CR4_PAE)) { + if (((context->ia32_efer & MSR_IA32_EFER_LME_BIT) != 0U) && + !paging_enabled && ((cr0 & CR0_PG) != 0U)) { + if ((context->cr4 & CR4_PAE) == 0U) { pr_err("Can't enable long mode when PAE disabled"); vcpu_inject_gp(vcpu, 0); return -EINVAL; @@ -355,8 +355,8 @@ int vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0) context->ia32_efer |= MSR_IA32_EFER_LMA_BIT; exec_vmwrite64(VMX_GUEST_IA32_EFER_FULL, context->ia32_efer); - } else if ((context->ia32_efer & MSR_IA32_EFER_LME_BIT) && - paging_enabled && !(cr0 & CR0_PG)){ + } else if (((context->ia32_efer & MSR_IA32_EFER_LME_BIT) != 0U) && + paging_enabled && ((cr0 & CR0_PG) == 0U)){ /* Disable long mode */ pr_dbg("VMM: Disable long mode"); entry_ctrls = exec_vmread(VMX_ENTRY_CONTROLS); @@ -436,14 +436,14 @@ int vmx_write_cr4(struct vcpu *vcpu, uint64_t cr4) * CR4, and inject a #GP to guest */ /* Check if guest try to set fixed to 0 bits or reserved bits */ - if(cr4 & cr4_always_off_mask) { + if((cr4 & cr4_always_off_mask) != 0U) { pr_err("Not allow to set reserved/always off bits for CR4"); vcpu_inject_gp(vcpu, 0); return -EINVAL; } /* Do NOT support nested guest */ - if (cr4 & CR4_VMXE) { + if ((cr4 & CR4_VMXE) != 0U) { pr_err("Nested guest not supported"); vcpu_inject_gp(vcpu, 0); return -EINVAL; @@ -620,7 +620,7 @@ static void init_guest_state(struct vcpu *vcpu) value32 = gdtb.limit; - if ((gdtb.base >> 47) & 0x1) + if (((gdtb.base >> 47) & 0x1) != 0U) gdtb.base |= 0xffff000000000000ull; base = gdtb.base; @@ -655,7 +655,7 @@ static void init_guest_state(struct vcpu *vcpu) /* Limit */ limit = idtb.limit; - if ((idtb.base >> 47) & 0x1) + if (((idtb.base >> 47) & 0x1) != 0U) idtb.base |= 0xffff000000000000ull; /* Base */ @@ -953,7 +953,7 @@ static void init_host_state(__unused struct vcpu *vcpu) asm volatile ("sgdt %0"::"m" (gdtb)); value32 = gdtb.limit; - if ((gdtb.base >> 47) & 0x1) + if (((gdtb.base >> 47) & 0x1) != 0U) gdtb.base |= 0xffff000000000000ull; /* Set up the guest and host GDTB base fields with current GDTB base */ @@ -963,7 +963,7 @@ static void init_host_state(__unused struct vcpu *vcpu) /* TODO: Should guest TR point to host TR ? */ trbase = gdtb.base + tr_sel; - if ((trbase >> 47) & 0x1) + if (((trbase >> 47) & 0x1) != 0U) trbase |= 0xffff000000000000ull; /* SS segment override */ @@ -989,7 +989,7 @@ static void init_host_state(__unused struct vcpu *vcpu) /* Obtain the current interrupt descriptor table base */ asm volatile ("sidt %0"::"m" (idtb)); /* base */ - if ((idtb.base >> 47) & 0x1) + if (((idtb.base >> 47) & 0x1) != 0U) idtb.base |= 0xffff000000000000ull; field = VMX_HOST_IDTR_BASE; @@ -1144,7 +1144,7 @@ static void init_exec_ctrl(struct vcpu *vcpu) VMX_PROCBASED_CTLS2_RDTSCP | VMX_PROCBASED_CTLS2_UNRESTRICT); - if (vcpu->arch_vcpu.vpid) + if (vcpu->arch_vcpu.vpid != 0) value32 |= VMX_PROCBASED_CTLS2_VPID; else value32 &= ~VMX_PROCBASED_CTLS2_VPID; @@ -1201,7 +1201,7 @@ static void init_exec_ctrl(struct vcpu *vcpu) } /* Check for EPT support */ - if (is_ept_supported()) + if (is_ept_supported() != 0) pr_dbg("EPT is supported"); else pr_err("Error: EPT is not supported"); diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index cd7e114be..44cf82dd0 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -175,7 +175,7 @@ static int register_hrhd_units(void) struct dmar_drhd_rt *drhd_rt; uint32_t i; - if (!info) { + if (info == NULL) { pr_warn("vtd: no dmar units found"); return -1; } @@ -232,7 +232,7 @@ static void iommu_flush_cache(struct dmar_drhd_rt *dmar_uint, uint32_t i; /* if vtd support page-walk coherency, no need to flush cacheline */ - if (iommu_ecap_c(dmar_uint->ecap)) + if (iommu_ecap_c(dmar_uint->ecap) != 0U) return; for (i = 0; i < size; i += CACHE_LINE_SIZE) @@ -326,7 +326,7 @@ static uint8_t dmar_uint_get_msagw(struct dmar_drhd_rt *dmar_uint) uint8_t sgaw = iommu_cap_sagaw(dmar_uint->cap); for (i = 4; i >= 0; i--) { - if ((1 << i) & sgaw) + if (((1 << i) & sgaw) != 0) break; } return (uint8_t)i; @@ -351,7 +351,7 @@ static void dmar_enable_translation(struct dmar_drhd_rt *dmar_uint) iommu_write32(dmar_uint, DMAR_GCMD_REG, dmar_uint->gcmd); /* 32-bit register */ - DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, status & DMA_GSTS_TES, status); + DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, (status & DMA_GSTS_TES) != 0U, status); status = iommu_read32(dmar_uint, DMAR_GSTS_REG); @@ -370,7 +370,7 @@ static void dmar_disable_translation(struct dmar_drhd_rt *dmar_uint) iommu_write32(dmar_uint, DMAR_GCMD_REG, dmar_uint->gcmd); /* 32-bit register */ - DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, !(status & DMA_GSTS_TES), status); + DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, (status & DMA_GSTS_TES) == 0U, status); IOMMU_UNLOCK(dmar_uint); } @@ -419,7 +419,7 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint) * How to guarantee it when EPT is used as second-level * translation paging structures? */ - if (!iommu_ecap_sc(dmar_uint->ecap)) + if (iommu_ecap_sc(dmar_uint->ecap) == 0U) dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support snoop control!"); @@ -432,14 +432,14 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint) max_domain_id = dmar_uint->max_domain_id; /* register operation is considered serial, no lock here */ - if (dmar_uint->drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) + if ((dmar_uint->drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) != 0U) list_add_tail(&dmar_uint->list, &dmar_drhd_units); else list_add(&dmar_uint->list, &dmar_drhd_units); dmar_hdrh_unit_count++; - if (dmar_uint->gcmd & DMA_GCMD_TE) + if ((dmar_uint->gcmd & DMA_GCMD_TE) != 0) dmar_disable_translation(dmar_uint); } @@ -465,7 +465,7 @@ static struct dmar_drhd_rt *device_to_dmaru(uint16_t segment, uint8_t bus, /* has the same segment number and * the dmar unit has INCLUDE_PCI_ALL set */ - if (dmar_uint->drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) + if ((dmar_uint->drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) != 0U) return dmar_uint; } @@ -519,7 +519,7 @@ static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint) { uint32_t status; - if (!iommu_cap_rwbf(dmar_uint->cap)) + if (iommu_cap_rwbf(dmar_uint->cap) == 0U) return; IOMMU_LOCK(dmar_uint); @@ -527,7 +527,7 @@ static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint) dmar_uint->gcmd | DMA_GCMD_WBF); /* read lower 32 bits to check */ - DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, !(status & DMA_GSTS_WBFS), status); + DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, (status & DMA_GSTS_WBFS) == 0U, status); IOMMU_UNLOCK(dmar_uint); } @@ -562,7 +562,7 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint, IOMMU_LOCK(dmar_uint); iommu_write64(dmar_uint, DMAR_CCMD_REG, cmd); /* read upper 32bits to check */ - DMAR_WAIT_COMPLETION(DMAR_CCMD_REG + 4, !(status & DMA_CCMD_ICC_32), + DMAR_WAIT_COMPLETION(DMAR_CCMD_REG + 4, (status & DMA_CCMD_ICC_32) == 0U, status); IOMMU_UNLOCK(dmar_uint); @@ -605,16 +605,16 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint, return; } IOMMU_LOCK(dmar_uint); - if (addr) + if (addr != 0U) iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset, addr); iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset + 8, cmd); /* read upper 32bits to check */ DMAR_WAIT_COMPLETION(dmar_uint->ecap_iotlb_offset + 12, - !(status & DMA_IOTLB_IVT_32), status); + (status & DMA_IOTLB_IVT_32) == 0U, status); IOMMU_UNLOCK(dmar_uint); - if (!DMA_IOTLB_GET_IAIG_32(status)) { + if (DMA_IOTLB_GET_IAIG_32(status) == 0U) { pr_err("fail to invalidate IOTLB!, 0x%x, 0x%x", status, iommu_read32(dmar_uint, DMAR_FSTS_REG)); } @@ -646,7 +646,7 @@ static void dmar_set_root_table(struct dmar_drhd_rt *dmar_uint) dmar_uint->gcmd | DMA_GCMD_SRTP); /* 32-bit register */ - DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, status & DMA_GSTS_RTPS, status); + DMAR_WAIT_COMPLETION(DMAR_GSTS_REG, (status & DMA_GSTS_RTPS) != 0U, status); IOMMU_UNLOCK(dmar_uint); } @@ -714,12 +714,12 @@ static void fault_status_analysis(uint32_t status) static void fault_record_analysis(__unused uint64_t low, uint64_t high) { - if (!DMA_FRCD_UP_F(high)) + if (DMA_FRCD_UP_F(high) == 0U) return; /* currently skip PASID related parsing */ pr_info("%s, Reason: 0x%x, SID: %x.%x.%x @0x%llx", - DMA_FRCD_UP_T(high) ? "Read/Atomic" : "Write", + (DMA_FRCD_UP_T(high) != 0U) ? "Read/Atomic" : "Write", DMA_FRCD_UP_FR(high), DMA_FRCD_UP_SID(high) >> 8, (DMA_FRCD_UP_SID(high) >> 3) & 0x1f, @@ -749,7 +749,7 @@ static int dmar_fault_handler(int irq, void *data) fault_status_analysis(fsr); #endif - while (DMA_FSTS_PPF(fsr)) { + while (DMA_FSTS_PPF(fsr) != 0U) { loop++; index = DMA_FSTS_FRI(fsr); record_reg_offset = dmar_uint->cap_fault_reg_offset @@ -792,7 +792,7 @@ static int dmar_setup_interrupt(struct dmar_drhd_rt *dmar_uint) { uint32_t vector; - if (dmar_uint->dmar_irq_node) { + if (dmar_uint->dmar_irq_node != NULL) { dev_dbg(ACRN_DBG_IOMMU, "%s: irq already setup", __func__); return 0; } @@ -802,7 +802,7 @@ static int dmar_setup_interrupt(struct dmar_drhd_rt *dmar_uint) dmar_uint, true, false, "dmar_fault_event"); - if (!dmar_uint->dmar_irq_node) { + if (dmar_uint->dmar_irq_node == NULL) { pr_err("%s: fail to setup interrupt", __func__); return 1; } @@ -832,7 +832,7 @@ static void dmar_enable(struct dmar_drhd_rt *dmar_uint) static void dmar_disable(struct dmar_drhd_rt *dmar_uint) { - if (dmar_uint->gcmd & DMA_GCMD_TE) + if ((dmar_uint->gcmd & DMA_GCMD_TE) != 0U) dmar_disable_translation(dmar_uint); dmar_fault_event_mask(dmar_uint); @@ -846,7 +846,7 @@ struct iommu_domain *create_iommu_domain(int vm_id, uint64_t translation_table, /* TODO: check if a domain with the vm_id exists */ - if (!translation_table) { + if (translation_table == 0) { pr_err("translation table is NULL"); return NULL; } @@ -882,7 +882,7 @@ struct iommu_domain *create_iommu_domain(int vm_id, uint64_t translation_table, int destroy_iommu_domain(struct iommu_domain *domain) { - if (!domain) + if (domain == NULL) return 1; /* currently only support ept */ @@ -913,11 +913,11 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, uint64_t upper = 0; uint64_t lower = 0; - if (!domain) + if (domain == NULL) return 1; dmar_uint = device_to_dmaru(segment, bus, devfun); - if (!dmar_uint) { + if (dmar_uint == NULL) { pr_err("no dmar unit found for device:0x%x:%x.%x", bus, devfun >> 3, devfun & 0x7); return 1; @@ -938,10 +938,10 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, if (dmar_uint->root_table_addr == 0) { void *root_table_vaddr = alloc_paging_struct(); - if (root_table_vaddr) { + if (root_table_vaddr != NULL) { dmar_uint->root_table_addr = HVA2HPA(root_table_vaddr); } else { - ASSERT(0, "failed to allocate root table!"); + ASSERT(false, "failed to allocate root table!"); return 1; } } @@ -950,10 +950,10 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, root_entry = (struct dmar_root_entry *)&root_table[bus * 2]; - if (!DMAR_GET_BITSLICE(root_entry->lower, ROOT_ENTRY_LOWER_PRESENT)) { + if (DMAR_GET_BITSLICE(root_entry->lower, ROOT_ENTRY_LOWER_PRESENT) == 0U) { void *vaddr = alloc_paging_struct(); - if (vaddr) { + if (vaddr != NULL) { /* create context table for the bus if not present */ context_table_addr = HVA2HPA(vaddr); @@ -969,7 +969,7 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, iommu_flush_cache(dmar_uint, root_entry, sizeof(struct dmar_root_entry)); } else { - ASSERT(0, "failed to allocate context table!"); + ASSERT(false, "failed to allocate context table!"); return 1; } } else { @@ -983,7 +983,7 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, context_entry = (struct dmar_context_entry *)&context_table[devfun * 2]; /* the context entry should not be present */ - if (DMAR_GET_BITSLICE(context_entry->lower, CTX_ENTRY_LOWER_P)) { + if (DMAR_GET_BITSLICE(context_entry->lower, CTX_ENTRY_LOWER_P) != 0U) { pr_err("%s: context entry@0x%llx (Lower:%x) ", __func__, context_entry, context_entry->lower); pr_err("already present for %x:%x.%x", @@ -995,7 +995,7 @@ static int add_iommu_device(struct iommu_domain *domain, uint16_t segment, upper = 0; lower = 0; if (domain->is_host) { - if (iommu_ecap_pt(dmar_uint->ecap)) { + if (iommu_ecap_pt(dmar_uint->ecap) != 0U) { /* When the Translation-type (T) field indicates * pass-through processing (10b), AW field must be * programmed to indicate the largest AGAW value @@ -1042,11 +1042,11 @@ remove_iommu_device(struct iommu_domain *domain, uint16_t segment, struct dmar_root_entry *root_entry; struct dmar_context_entry *context_entry; - if (!domain) + if (domain == NULL) return 1; dmar_uint = device_to_dmaru(segment, bus, devfun); - if (!dmar_uint) { + if (dmar_uint == NULL) { pr_err("no dmar unit found for device:0x%x:%x", bus, devfun); return 1; @@ -1085,7 +1085,7 @@ remove_iommu_device(struct iommu_domain *domain, uint16_t segment, int assign_iommu_device(struct iommu_domain *domain, uint8_t bus, uint8_t devfun) { - if (!domain) + if (domain == NULL) return 1; /* TODO: check if the device assigned */ @@ -1098,7 +1098,7 @@ int assign_iommu_device(struct iommu_domain *domain, uint8_t bus, int unassign_iommu_device(struct iommu_domain *domain, uint8_t bus, uint8_t devfun) { - if (!domain) + if (domain == NULL) return 1; /* TODO: check if the device assigned */ @@ -1223,7 +1223,7 @@ int init_iommu(void) spinlock_init(&domain_lock); - if (register_hrhd_units()) + if (register_hrhd_units() != 0) return -1; host_domain = create_host_domain(); diff --git a/hypervisor/boot/acpi.c b/hypervisor/boot/acpi.c index fe62fc37a..9d5b704c0 100644 --- a/hypervisor/boot/acpi.c +++ b/hypervisor/boot/acpi.c @@ -114,8 +114,8 @@ biosacpi_search_rsdp(char *base, int length) rsdp = (struct acpi_table_rsdp *)(base + ofs); /* compare signature, validate checksum */ - if (!strncmp(rsdp->signature, ACPI_SIG_RSDP, - strnlen_s(ACPI_SIG_RSDP, 8))) { + if (strncmp(rsdp->signature, ACPI_SIG_RSDP, + strnlen_s(ACPI_SIG_RSDP, 8)) == 0) { cp = (uint8_t *)rsdp; sum = 0; for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++) @@ -179,7 +179,7 @@ void *get_acpi_tbl(char *sig) rsdp = (struct acpi_table_rsdp *)global_rsdp; - if (rsdp->revision >= 2 && rsdp->xsdt_physical_address) { + if (rsdp->revision >= 2 && (rsdp->xsdt_physical_address != 0U)) { /* * AcpiOsGetRootPointer only verifies the checksum for * the version 1.0 portion of the RSDP. Version 2.0 has @@ -191,7 +191,7 @@ void *get_acpi_tbl(char *sig) sizeof(uint64_t); for (i = 0; i < count; i++) { - if (probe_table(xsdt->table_offset_entry[i], sig)) { + if (probe_table(xsdt->table_offset_entry[i], sig) != 0) { addr = xsdt->table_offset_entry[i]; break; } @@ -205,7 +205,7 @@ void *get_acpi_tbl(char *sig) sizeof(uint32_t); for (i = 0; i < count; i++) { - if (probe_table(rsdt->table_offset_entry[i], sig)) { + if (probe_table(rsdt->table_offset_entry[i], sig) != 0) { addr = rsdt->table_offset_entry[i]; break; } @@ -235,7 +235,7 @@ static int _parse_madt(void *madt, uint8_t *lapic_id_base) if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) { processor = (struct acpi_madt_local_apic *)entry; - if (processor->lapic_flags & ACPI_MADT_ENABLED) { + if ((processor->lapic_flags & ACPI_MADT_ENABLED) != 0U) { *lapic_id_base++ = processor->id; pcpu_id++; } diff --git a/hypervisor/boot/sbl/multiboot.c b/hypervisor/boot/sbl/multiboot.c index cdb34388b..32795f927 100644 --- a/hypervisor/boot/sbl/multiboot.c +++ b/hypervisor/boot/sbl/multiboot.c @@ -42,7 +42,7 @@ static void parse_other_modules(struct vm *vm, start++; end = start; - while (*end != ' ' && *end) + while (*end != ' ' && (*end) != 0) end++; type_len = end - start; @@ -58,7 +58,7 @@ static void parse_other_modules(struct vm *vm, dev_dbg(ACRN_DBG_BOOT, "fw-%d: %s", i, dyn_bootargs); /*copy boot args to load addr, set src=load addr*/ - if (copy_once) { + if (copy_once != 0) { copy_once = 0; strcpy_s(load_addr, MEM_2K, vm->sw.linux_info.bootargs_src_addr); @@ -95,7 +95,7 @@ static void *get_kernel_load_addr(void *kernel_src_addr) * non-relocatable. */ zeropage = (struct zero_page *)kernel_src_addr; - if (zeropage->hdr.relocatable_kernel) + if (zeropage->hdr.relocatable_kernel != 0U) return (void *)zeropage->hdr.pref_addr; return kernel_src_addr; @@ -112,15 +112,15 @@ int init_vm0_boot_info(struct vm *vm) } if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) { - ASSERT(0, "no multiboot info found"); + ASSERT(false, "no multiboot info found"); return -EINVAL; } mbi = (struct multiboot_info *)((uint64_t)boot_regs[1]); dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags); - if (!(mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS)) { - ASSERT(0, "no sos kernel info found"); + if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) { + ASSERT(false, "no sos kernel info found"); return -EINVAL; } @@ -147,7 +147,7 @@ int init_vm0_boot_info(struct vm *vm) * If there is cmdline from mbi->mi_cmdline, merge it with * mods[0].mm_string */ - if (mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) { + if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) { char *cmd_src, *cmd_dst; int off = 0; diff --git a/hypervisor/bsp/uefi/efi/boot.c b/hypervisor/bsp/uefi/efi/boot.c index c04aad550..3d85cc086 100644 --- a/hypervisor/bsp/uefi/efi/boot.c +++ b/hypervisor/bsp/uefi/efi/boot.c @@ -170,7 +170,7 @@ again: continue; } - if (j && mmap[j-1].mm_type == e820_type && + if ((j != 0) && mmap[j-1].mm_type == e820_type && (mmap[j-1].mm_base_addr + mmap[j-1].mm_length) == d->PhysicalStart) { mmap[j-1].mm_length += d->NumberOfPages << EFI_PAGE_SHIFT; @@ -247,7 +247,7 @@ switch_to_guest_mode(EFI_HANDLE image) config_table++; } - if (!rsdp) { + if (rsdp == NULL) { Print(L"unable to find RSDP\n"); goto out; } diff --git a/hypervisor/bsp/uefi/uefi.c b/hypervisor/bsp/uefi/uefi.c index 593138f52..e48797f73 100644 --- a/hypervisor/bsp/uefi/uefi.c +++ b/hypervisor/bsp/uefi/uefi.c @@ -39,9 +39,9 @@ void efi_spurious_handler(int vector) return; vcpu = per_cpu(vcpu, 0); - if (vcpu && vcpu->arch_vcpu.vlapic) { + if ((vcpu != NULL) && vcpu->arch_vcpu.vlapic) { ret = vlapic_set_intr(vcpu, vector, 0); - if (ret) + if (ret != 0) pr_err("%s vlapic set intr fail, interrupt lost\n", __func__); } else diff --git a/hypervisor/lib/memory.c b/hypervisor/lib/memory.c index 92df2461a..fa50c4a5a 100644 --- a/hypervisor/lib/memory.c +++ b/hypervisor/lib/memory.c @@ -79,7 +79,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes) for (bit_idx = ffz64(pool->bitmap[idx]); bit_idx < BITMAP_WORD_SIZE; bit_idx++) { /* Check if selected buffer is free */ - if (pool->bitmap[idx] & (1 << bit_idx)) + if ((pool->bitmap[idx] & (1 << bit_idx)) != 0U) continue; /* Declare temporary variables to be used locally in @@ -105,7 +105,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes) } /* Break if selected buffer is not free */ - if (pool->bitmap[tmp_idx] & (1 << tmp_bit_idx)) + if ((pool->bitmap[tmp_idx] & (1 << tmp_bit_idx)) != 0U) break; } @@ -201,13 +201,13 @@ static void deallocate_mem(struct mem_pool *pool, void *ptr) contiguity_bitmask = &pool->contiguity_bitmap[bmp_idx]; /* Mark the buffer as free */ - if (*bitmask & (1 << bit_idx)) + if ((*bitmask & (1 << bit_idx)) != 0U) *bitmask ^= (1 << bit_idx); else break; /* Reset the Contiguity bit of buffer */ - if (*contiguity_bitmask & (1 << bit_idx)) + if ((*contiguity_bitmask & (1 << bit_idx)) != 0U) *contiguity_bitmask ^= (1 << bit_idx); else break; @@ -362,7 +362,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen) /*small data block*/ if (slen < 8) { - while (slen) { + while (slen != 0U) { *dest8++ = *src8++; slen--; } @@ -372,7 +372,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen) /*make sure 8bytes-aligned for at least one addr.*/ if ((!MEM_ALIGNED_CHECK(src8, 8)) && (!MEM_ALIGNED_CHECK(dest8, 8))) { - for (; slen && (((uint64_t)src8) & 7); slen--) + for (; slen != 0U && (((uint64_t)src8) & 7) != 0; slen--) *dest8++ = *src8++; } @@ -389,7 +389,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen) } /*tail bytes*/ - while (slen) { + while (slen != 0U) { *dest8++ = *src8++; slen--; } @@ -410,7 +410,7 @@ void *memset(void *base, uint8_t v, size_t n) /*do the few bytes to get uint64_t alignment*/ count = n; - for (; count && ((uint64_t)dest_p & 7); count--) + for (; count != 0U && ((uint64_t)dest_p & 7) != 0U; count--) *dest_p++ = v; /*64-bit mode*/ diff --git a/hypervisor/lib/sprintf.c b/hypervisor/lib/sprintf.c index 85764af28..80db0927c 100644 --- a/hypervisor/lib/sprintf.c +++ b/hypervisor/lib/sprintf.c @@ -97,7 +97,7 @@ static const char *get_int(const char *s, int *x) *x = *x * 10 + (*s++ - '0'); /* apply sign to result */ - if (negative) + if (negative != 0) *x = -*x; return s; @@ -118,7 +118,7 @@ static const char *get_flags(const char *s, int *flags) const char *pos; /* parse multiple flags */ - while (*s) { + while ((*s) != 0) { /* get index of flag. Terminate loop if no flag character was * found */ @@ -132,11 +132,11 @@ static const char *get_flags(const char *s, int *flags) } /* Spec says that '-' has a higher priority than '0' */ - if (*flags & PRINT_FLAG_LEFT_JUSTIFY) + if ((*flags & PRINT_FLAG_LEFT_JUSTIFY) != 0) *flags &= ~PRINT_FLAG_PAD_ZERO; /* Spec says that '+' has a higher priority than ' ' */ - if (*flags & PRINT_FLAG_SIGN) + if ((*flags & PRINT_FLAG_SIGN) != 0) *flags &= ~PRINT_FLAG_SPACE; return s; @@ -203,14 +203,14 @@ static int format_number(struct print_param *param) * used for padding, the prefix is emitted after the padding. */ - if (param->vars.flags & PRINT_FLAG_PAD_ZERO) { + if ((param->vars.flags & PRINT_FLAG_PAD_ZERO) != 0) { /* use '0' for padding */ pad = '0'; /* emit prefix, return early if an error occurred */ res = param->emit(PRINT_CMD_COPY, param->vars.prefix, param->vars.prefixlen, param->data); - if (param->vars.prefix && (res < 0)) + if ((param->vars.prefix != NULL) && (res < 0)) return res; /* invalidate prefix */ @@ -229,7 +229,7 @@ static int format_number(struct print_param *param) /* emit prefix (if any), return early in case of an error */ res = param->emit(PRINT_CMD_COPY, param->vars.prefix, param->vars.prefixlen, param->data); - if (param->vars.prefix && (res < 0)) + if ((param->vars.prefix != NULL) && (res < 0)) return res; /* insert additional 0's for precision, return early if an error @@ -276,14 +276,14 @@ static int print_pow2(struct print_param *param, mask = (1ULL << shift) - 1; /* determine digit translation table */ - digits = (param->vars.flags & PRINT_FLAG_UPPER) ? + digits = ((param->vars.flags & PRINT_FLAG_UPPER) != 0) ? upper_hex_digits : lower_hex_digits; /* apply mask for short/char */ v &= param->vars.mask; /* determine prefix for alternate form */ - if ((v == 0) && (param->vars.flags & PRINT_FLAG_ALTERNATE_FORM)) { + if ((v == 0) && ((param->vars.flags & PRINT_FLAG_ALTERNATE_FORM) != 0)) { prefix[0] = '0'; param->vars.prefix = prefix; param->vars.prefixlen = 1; @@ -297,7 +297,7 @@ static int print_pow2(struct print_param *param, /* determine digits from right to left */ do { *--pos = digits[(v & mask)]; - } while (v >>= shift); + } while ((v >>= shift) != 0); /* assign parameter and apply width and precision */ param->vars.value = pos; @@ -339,11 +339,11 @@ static int print_decimal(struct print_param *param, int64_t value) } /* determine sign if explicit requested in the format string */ - if (!param->vars.prefix) { - if (param->vars.flags & PRINT_FLAG_SIGN) { + if (param->vars.prefix == NULL) { + if ((param->vars.flags & PRINT_FLAG_SIGN) != 0) { param->vars.prefix = "+"; param->vars.prefixlen = 1; - } else if (param->vars.flags & PRINT_FLAG_SPACE) { + } else if ((param->vars.flags & PRINT_FLAG_SPACE) != 0) { param->vars.prefix = " "; param->vars.prefixlen = 1; } @@ -396,11 +396,11 @@ static int print_string(struct print_param *param, const char *s) /* we need the length of the string if either width or precision is * given */ - if (param->vars.precision || param->vars.width) + if ((param->vars.precision != 0)|| (param->vars.width != 0)) len = strnlen_s(s, PRINT_STRING_MAX_LEN); /* precision gives the max. number of characters to emit. */ - if (param->vars.precision && (len > param->vars.precision)) + if ((param->vars.precision != 0) && (len > param->vars.precision)) len = param->vars.precision; /* calculate the number of additional characters to get the required @@ -426,7 +426,7 @@ static int print_string(struct print_param *param, const char *s) /* emit additional characters on the right, return early if an error * occurred */ - if (param->vars.flags & PRINT_FLAG_LEFT_JUSTIFY) { + if ((param->vars.flags & PRINT_FLAG_LEFT_JUSTIFY) != 0) { res = param->emit(PRINT_CMD_FILL, " ", w, param->data); if (res < 0) return res; @@ -446,11 +446,11 @@ int do_print(const char *fmt, struct print_param *param, const char *start; /* main loop: analyse until there are no more characters */ - while (*fmt) { + while ((*fmt) != 0) { /* mark the current position and search the next '%' */ start = fmt; - while (*fmt && (*fmt != '%')) + while (((*fmt) != 0) && (*fmt != '%')) fmt++; /* @@ -500,8 +500,8 @@ int do_print(const char *fmt, struct print_param *param, /* decimal number */ else if ((ch == 'd') || (ch == 'i')) { res = print_decimal(param, - (param->vars.flags & - PRINT_FLAG_LONG_LONG) ? + ((param->vars.flags & + PRINT_FLAG_LONG_LONG) != 0) ? __builtin_va_arg(args, long long) : (long long) @@ -512,8 +512,8 @@ int do_print(const char *fmt, struct print_param *param, else if (ch == 'u') { param->vars.flags |= PRINT_FLAG_UINT32; res = print_decimal(param, - (param->vars.flags & - PRINT_FLAG_LONG_LONG) ? + ((param->vars.flags & + PRINT_FLAG_LONG_LONG) != 0) ? __builtin_va_arg(args, unsigned long long) : (unsigned long long) @@ -523,8 +523,8 @@ int do_print(const char *fmt, struct print_param *param, /* octal number */ else if (ch == 'o') { res = print_pow2(param, - (param->vars.flags & - PRINT_FLAG_LONG_LONG) ? + ((param->vars.flags & + PRINT_FLAG_LONG_LONG) != 0) ? __builtin_va_arg(args, unsigned long long) : (unsigned long long) @@ -537,8 +537,8 @@ int do_print(const char *fmt, struct print_param *param, if (ch == 'X') param->vars.flags |= PRINT_FLAG_UPPER; res = print_pow2(param, - (param->vars.flags & - PRINT_FLAG_LONG_LONG) ? + ((param->vars.flags & + PRINT_FLAG_LONG_LONG) != 0) ? __builtin_va_arg(args, unsigned long long) : (unsigned long long) @@ -599,7 +599,7 @@ static int charmem(int cmd, const char *s, int sz, void *hnd) /* copy mode ? */ if (cmd == PRINT_CMD_COPY) { if (sz < 0) { - while (*s) { + while ((*s) != 0) { if (n < param->sz - param->wrtn) *p = *s; p++; @@ -608,7 +608,7 @@ static int charmem(int cmd, const char *s, int sz, void *hnd) } } else if (sz > 0) { - while (*s && n < sz) { + while (((*s) != 0) && n < sz) { if (n < param->sz - param->wrtn) *p = *s; p++; @@ -636,7 +636,7 @@ int vsnprintf(char *dst, int sz, const char *fmt, va_list args) /* the result of this function */ int res = 0; - if (sz <= 0 || !dst) { + if (sz <= 0 || (dst == NULL)) { dst = c; sz = 1; } diff --git a/hypervisor/lib/string.c b/hypervisor/lib/string.c index b363abebb..ad866324d 100644 --- a/hypervisor/lib/string.c +++ b/hypervisor/lib/string.c @@ -222,7 +222,7 @@ strtol(const char *nptr, char **endptr, register int base) */ do { c = *s++; - } while (ISSPACE(c)); + } while (ISSPACE(c) != 0U); if (c == '-') { neg = 1; c = *s++; @@ -254,14 +254,14 @@ strtol(const char *nptr, char **endptr, register int base) * Set any if any `digits' consumed; make it negative to indicate * overflow. */ - cutoff = neg ? -(uint64_t)LONG_MIN : LONG_MAX; + cutoff = (neg != 0) ? -(uint64_t)LONG_MIN : LONG_MAX; cutlim = cutoff % (uint64_t)base; cutoff /= (uint64_t)base; for (acc = 0, any = 0;; c = *s++) { - if (ISDIGIT(c)) + if (ISDIGIT(c) != 0U) c -= '0'; - else if (ISALPHA(c)) - c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; + else if (ISALPHA(c) != 0U) + c -= (ISUPPER(c) != 0U) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) @@ -275,11 +275,11 @@ strtol(const char *nptr, char **endptr, register int base) } } if (any < 0) - acc = neg ? LONG_MIN : LONG_MAX; - else if (neg) + acc = (neg != 0) ? LONG_MIN : LONG_MAX; + else if (neg != 0) acc = -acc; if (endptr != NULL) - *endptr = (char *) (any ? s - 1 : nptr); + *endptr = (char *) ((any != 0) ? s - 1 : nptr); return acc; } @@ -303,7 +303,7 @@ strtoul(const char *nptr, char **endptr, register int base) */ do { c = *s++; - } while (ISSPACE(c)); + } while (ISSPACE(c) != 0U); if (c == '-') { neg = 1; c = *s++; @@ -320,10 +320,10 @@ strtoul(const char *nptr, char **endptr, register int base) cutoff = (uint64_t)ULONG_MAX / (uint64_t)base; cutlim = (uint64_t)ULONG_MAX % (uint64_t)base; for (acc = 0, any = 0;; c = *s++) { - if (ISDIGIT(c)) + if (ISDIGIT(c) != 0U) c -= '0'; - else if (ISALPHA(c)) - c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; + else if (ISALPHA(c) != 0U) + c -= (ISUPPER(c) != 0U) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) @@ -338,10 +338,10 @@ strtoul(const char *nptr, char **endptr, register int base) } if (any < 0) acc = ULONG_MAX; - else if (neg) + else if (neg != 0) acc = -acc; if (endptr != NULL) - *endptr = (char *) (any ? s - 1 : nptr); + *endptr = (char *) ((any != 0) ? s - 1 : nptr); return acc; } @@ -353,10 +353,10 @@ atoi(const char *str) char *strchr(const char *s, int ch) { - while (*s && (*s != ch)) + while ((*s != 0) && (*s != ch)) ++s; - return (*s) ? ((char *)s) : 0; + return ((*s) != 0) ? ((char *)s) : 0; } /** @@ -540,7 +540,7 @@ size_t strnlen_s(const char *str, size_t maxlen) return 0; count = 0; - while (*str) { + while ((*str) != 0) { if (maxlen == 0) break; @@ -563,7 +563,7 @@ char hexdigit(int decimal_val) int strcmp(const char *s1, const char *s2) { - while (*s1 && *s2 && *s1 == *s2) { + while (((*s1) != 0) && ((*s2) != 0) && ((*s1) == (*s2))) { s1++; s2++; } @@ -573,7 +573,7 @@ int strcmp(const char *s1, const char *s2) int strncmp(const char *s1, const char *s2, size_t n) { - while (n - 1 && *s1 && *s2 && *s1 == *s2) { + while (((n - 1) != 0) && ((*s1) != 0) && ((*s2) != 0) && ((*s1) == (*s2))) { s1++; s2++; n--;