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 <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Huihuang Shi 2018-06-20 13:28:25 +08:00 committed by lijinxia
parent f92931c879
commit be0f5e6c16
17 changed files with 157 additions and 157 deletions

View File

@ -224,12 +224,12 @@ int shutdown_vm(struct vm *vm)
free_io_emulation_resource(vm); free_io_emulation_resource(vm);
/* Free iommu_domain */ /* Free iommu_domain */
if (vm->iommu_domain) if (vm->iommu_domain != NULL)
destroy_iommu_domain(vm->iommu_domain); destroy_iommu_domain(vm->iommu_domain);
bitmap_clear(vm->attr.id, &vmid_bitmap); bitmap_clear(vm->attr.id, &vmid_bitmap);
if (vm->vpic) if (vm->vpic != NULL)
vpic_cleanup(vm); vpic_cleanup(vm);
free(vm->hw.vcpu_array); free(vm->hw.vcpu_array);

View File

@ -90,7 +90,7 @@ void init_msr_emulation(struct vcpu *vcpu)
/* Allocate and initialize memory for MSR bitmap region*/ /* Allocate and initialize memory for MSR bitmap region*/
vcpu->vm->arch_vm.msr_bitmap = alloc_page(); 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); memset(vcpu->vm->arch_vm.msr_bitmap, 0x0, CPU_PAGE_SIZE);
msr_bitmap = vcpu->vm->arch_vm.msr_bitmap; msr_bitmap = vcpu->vm->arch_vm.msr_bitmap;
@ -307,7 +307,7 @@ int wrmsr_vmexit_handler(struct vcpu *vcpu)
} }
case MSR_IA32_PERF_CTL: case MSR_IA32_PERF_CTL:
{ {
if (validate_pstate(vcpu->vm, v)) { if (validate_pstate(vcpu->vm, v) != 0) {
break; break;
} }
msr_write(msr, v); msr_write(msr, v);

View File

@ -164,7 +164,7 @@ static void clear_lapic_isr(void)
* life, therefore we will ensure all the in-service bits are clear. * life, therefore we will ensure all the in-service bits are clear.
*/ */
do { do {
if (read_lapic_reg32(isr_reg)) { if (read_lapic_reg32(isr_reg) != 0U) {
write_lapic_reg32(LAPIC_EOI_REGISTER, 0); write_lapic_reg32(LAPIC_EOI_REGISTER, 0);
continue; continue;
} }
@ -328,7 +328,7 @@ static void wait_for_delivery(void)
do { do {
tmp.value_32.lo_32 = tmp.value_32.lo_32 =
read_lapic_reg32(LAPIC_INT_COMMAND_REGISTER_0); 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) uint32_t get_cur_lapic_id(void)

View File

@ -63,7 +63,7 @@ void setup_notification(void)
void cleanup_notification(void) void cleanup_notification(void)
{ {
if (notification_node) if (notification_node != NULL)
unregister_handler_common(notification_node); unregister_handler_common(notification_node);
notification_node = NULL; notification_node = NULL;
} }

View File

@ -81,7 +81,7 @@ again:
CPU_IRQ_DISABLE(); CPU_IRQ_DISABLE();
if (((*bitmap) & SOFTIRQ_MASK)) if (((*bitmap) & SOFTIRQ_MASK) != 0U)
goto again; goto again;
enable_softirq(cpu_id); enable_softirq(cpu_id);

View File

@ -16,7 +16,7 @@ uint64_t tsc_hz = 1000000000;
static void run_timer(struct timer *timer) static void run_timer(struct timer *timer)
{ {
/* deadline = 0 means stop timer, we should skip */ /* 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); timer->func(timer->priv_data);
TRACE_2L(TRACE_TIMER_ACTION_PCKUP, timer->fire_tsc, 0); 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); list_add(&timer->node, prev);
if (need_update) if (need_update != NULL)
/* update the physical timer if we're on the timer_list head */ /* update the physical timer if we're on the timer_list head */
*need_update = (prev == &cpu_timer->timer_list); *need_update = (prev == &cpu_timer->timer_list);
} }
@ -95,7 +95,7 @@ int add_timer(struct timer *timer)
void del_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); list_del_init(&timer->node);
} }
@ -108,7 +108,7 @@ static int request_timer_irq(int pcpu_id,
if (pcpu_id >= phy_cpu_num) if (pcpu_id >= phy_cpu_num)
return -EINVAL; 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); pr_err("CPU%d timer isr already added", pcpu_id);
unregister_handler_common(per_cpu(timer_node, 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(); 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)); unregister_handler_common(per_cpu(timer_node, pcpu_id));
per_cpu(timer_node, pcpu_id) = NULL; per_cpu(timer_node, pcpu_id) = NULL;
@ -286,7 +286,7 @@ static uint64_t native_calibrate_tsc(void)
void calibrate_tsc(void) void calibrate_tsc(void)
{ {
tsc_hz = native_calibrate_tsc(); tsc_hz = native_calibrate_tsc();
if (!tsc_hz) if (tsc_hz == 0U)
tsc_hz = pit_calibrate_tsc(CAL_MS); tsc_hz = pit_calibrate_tsc(CAL_MS);
printf("%s, tsc_hz=%lu\n", __func__, tsc_hz); printf("%s, tsc_hz=%lu\n", __func__, tsc_hz);
} }

View File

@ -315,12 +315,12 @@ static bool setup_trusty_info(struct vcpu *vcpu,
/* Derive dvseed from dseed for Trusty */ /* Derive dvseed from dseed for Trusty */
key_info = &mem->first_page.data.key_info; key_info = &mem->first_page.data.key_info;
for (i = 0; i < g_key_info.num_seeds; i++) { 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, BUP_MKHI_BOOTLOADER_SEED_LEN,
g_key_info.dseed_list[i].seed, g_key_info.dseed_list[i].seed,
BUP_MKHI_BOOTLOADER_SEED_LEN, BUP_MKHI_BOOTLOADER_SEED_LEN,
NULL, 0, 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)); memset(key_info, 0, sizeof(struct key_info));
pr_err("%s: derive dvseed failed!", __func__); pr_err("%s: derive dvseed failed!", __func__);
return false; return false;
@ -402,12 +402,12 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
return false; return false;
} }
if (!boot_param->entry_point) { if (boot_param->entry_point == 0) {
pr_err("%s: Invalid entry point\n", __func__); pr_err("%s: Invalid entry point\n", __func__);
return false; return false;
} }
if (!boot_param->base_addr) { if (boot_param->base_addr == 0) {
pr_err("%s: Invalid memory base address\n", __func__); pr_err("%s: Invalid memory base address\n", __func__);
return false; return false;
} }

View File

@ -143,14 +143,14 @@ int vmexit_handler(struct vcpu *vcpu)
vcpu->arch_vcpu.idt_vectoring_info = vcpu->arch_vcpu.idt_vectoring_info =
exec_vmread(VMX_IDT_VEC_INFO_FIELD); exec_vmread(VMX_IDT_VEC_INFO_FIELD);
/* Filter out HW exception & NMI */ /* 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_info = vcpu->arch_vcpu.idt_vectoring_info;
uint32_t vector = vector_info & 0xff; uint32_t vector = vector_info & 0xff;
uint32_t type = (vector_info & VMX_INT_TYPE_MASK) >> 8; uint32_t type = (vector_info & VMX_INT_TYPE_MASK) >> 8;
uint32_t err_code = 0; uint32_t err_code = 0;
if (type == VMX_INT_TYPE_HW_EXP) { 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); err_code = exec_vmread(VMX_IDT_VEC_ERROR_CODE);
vcpu_queue_exception(vcpu, vector, err_code); vcpu_queue_exception(vcpu, vector, err_code);
vcpu->arch_vcpu.idt_vectoring_info = 0; 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 /* See if an exit qualification is necessary for this exit
* handler * handler
*/ */
if (dispatch->need_exit_qualification) { if (dispatch->need_exit_qualification != 0U) {
/* Get exit qualification */ /* Get exit qualification */
vcpu->arch_vcpu.exit_qualification = vcpu->arch_vcpu.exit_qualification =
exec_vmread(VMX_EXIT_QUALIFICATION); exec_vmread(VMX_EXIT_QUALIFICATION);
@ -306,7 +306,7 @@ static int xsetbv_vmexit_handler(struct vcpu *vcpu)
struct run_context *ctx_ptr; struct run_context *ctx_ptr;
val64 = exec_vmread(VMX_GUEST_CR4); val64 = exec_vmread(VMX_GUEST_CR4);
if (!(val64 & CR4_OSXSAVE)) { if ((val64 & CR4_OSXSAVE) == 0U) {
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -1; return -1;
} }
@ -327,7 +327,7 @@ static int xsetbv_vmexit_handler(struct vcpu *vcpu)
(ctx_ptr->guest_cpu_regs.regs.rdx << 32); (ctx_ptr->guest_cpu_regs.regs.rdx << 32);
/*bit 0(x87 state) of XCR0 can't be cleared*/ /*bit 0(x87 state) of XCR0 can't be cleared*/
if (!(val64 & 0x01)) { if ((val64 & 0x01) == 0U) {
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -1; return -1;
} }

View File

@ -47,9 +47,9 @@ static inline int exec_vmxon(void *addr)
tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL); tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL);
/* Determine if feature control is locked */ /* 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 */ /* 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 */ /* Return error - VMX can't be enabled */
pr_err("%s, VMX can't be enabled\n", __func__); pr_err("%s, VMX can't be enabled\n", __func__);
status = -EINVAL; status = -EINVAL;
@ -72,7 +72,7 @@ static inline int exec_vmxon(void *addr)
: "%rax", "cc", "memory"); : "%rax", "cc", "memory");
/* if carry and zero flags are clear operation success */ /* 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__); pr_err("%s, Turn VMX on failed\n", __func__);
status = -EINVAL; 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); per_cpu(vmxon_region_pa, pcpu_id) = HVA2HPA(vmxon_region_va);
ret = exec_vmxon(&per_cpu(vmxon_region_pa, pcpu_id)); ret = exec_vmxon(&per_cpu(vmxon_region_pa, pcpu_id));
if (vcpu) { if (vcpu != NULL) {
vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs);
ret = exec_vmptrld(&vmcs_pa); ret = exec_vmptrld(&vmcs_pa);
} }
@ -135,10 +135,10 @@ int vmx_off(int pcpu_id)
struct vcpu *vcpu = get_ever_run_vcpu(pcpu_id); struct vcpu *vcpu = get_ever_run_vcpu(pcpu_id);
uint64_t vmcs_pa; uint64_t vmcs_pa;
if (vcpu) { if (vcpu != NULL) {
vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs); vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs);
ret = exec_vmclear((void *)&vmcs_pa); ret = exec_vmclear((void *)&vmcs_pa);
if (ret) if (ret != 0)
return ret; return ret;
} }
@ -165,7 +165,7 @@ int exec_vmclear(void *addr)
: "%rax", "cc", "memory"); : "%rax", "cc", "memory");
/* if carry and zero flags are clear operation success */ /* if carry and zero flags are clear operation success */
if (rflags & (RFLAGS_C | RFLAGS_Z)) if ((rflags & (RFLAGS_C | RFLAGS_Z)) != 0U)
status = -EINVAL; status = -EINVAL;
return status; return status;
@ -190,7 +190,7 @@ int exec_vmptrld(void *addr)
: "%rax", "cc"); : "%rax", "cc");
/* if carry and zero flags are clear operation success */ /* if carry and zero flags are clear operation success */
if (rflags & (RFLAGS_C | RFLAGS_Z)) if ((rflags & (RFLAGS_C | RFLAGS_Z)) != 0U)
status = -EINVAL; status = -EINVAL;
return status; return status;
@ -331,7 +331,7 @@ int vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0)
uint32_t entry_ctrls; uint32_t entry_ctrls;
bool paging_enabled = !!(context->cr0 & CR0_PG); 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"); pr_err("Not allow to set always off / reserved bits for CR0");
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -EINVAL; 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 /* TODO: Check all invalid guest statuses according to the change of
* CR0, and inject a #GP to guest */ * CR0, and inject a #GP to guest */
if ((context->ia32_efer & MSR_IA32_EFER_LME_BIT) && if (((context->ia32_efer & MSR_IA32_EFER_LME_BIT) != 0U) &&
!paging_enabled && (cr0 & CR0_PG)) { !paging_enabled && ((cr0 & CR0_PG) != 0U)) {
if (!(context->cr4 & CR4_PAE)) { if ((context->cr4 & CR4_PAE) == 0U) {
pr_err("Can't enable long mode when PAE disabled"); pr_err("Can't enable long mode when PAE disabled");
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -EINVAL; return -EINVAL;
@ -355,8 +355,8 @@ int vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0)
context->ia32_efer |= MSR_IA32_EFER_LMA_BIT; context->ia32_efer |= MSR_IA32_EFER_LMA_BIT;
exec_vmwrite64(VMX_GUEST_IA32_EFER_FULL, context->ia32_efer); exec_vmwrite64(VMX_GUEST_IA32_EFER_FULL, context->ia32_efer);
} else if ((context->ia32_efer & MSR_IA32_EFER_LME_BIT) && } else if (((context->ia32_efer & MSR_IA32_EFER_LME_BIT) != 0U) &&
paging_enabled && !(cr0 & CR0_PG)){ paging_enabled && ((cr0 & CR0_PG) == 0U)){
/* Disable long mode */ /* Disable long mode */
pr_dbg("VMM: Disable long mode"); pr_dbg("VMM: Disable long mode");
entry_ctrls = exec_vmread(VMX_ENTRY_CONTROLS); 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 */ * CR4, and inject a #GP to guest */
/* Check if guest try to set fixed to 0 bits or reserved bits */ /* 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"); pr_err("Not allow to set reserved/always off bits for CR4");
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -EINVAL; return -EINVAL;
} }
/* Do NOT support nested guest */ /* Do NOT support nested guest */
if (cr4 & CR4_VMXE) { if ((cr4 & CR4_VMXE) != 0U) {
pr_err("Nested guest not supported"); pr_err("Nested guest not supported");
vcpu_inject_gp(vcpu, 0); vcpu_inject_gp(vcpu, 0);
return -EINVAL; return -EINVAL;
@ -620,7 +620,7 @@ static void init_guest_state(struct vcpu *vcpu)
value32 = gdtb.limit; value32 = gdtb.limit;
if ((gdtb.base >> 47) & 0x1) if (((gdtb.base >> 47) & 0x1) != 0U)
gdtb.base |= 0xffff000000000000ull; gdtb.base |= 0xffff000000000000ull;
base = gdtb.base; base = gdtb.base;
@ -655,7 +655,7 @@ static void init_guest_state(struct vcpu *vcpu)
/* Limit */ /* Limit */
limit = idtb.limit; limit = idtb.limit;
if ((idtb.base >> 47) & 0x1) if (((idtb.base >> 47) & 0x1) != 0U)
idtb.base |= 0xffff000000000000ull; idtb.base |= 0xffff000000000000ull;
/* Base */ /* Base */
@ -953,7 +953,7 @@ static void init_host_state(__unused struct vcpu *vcpu)
asm volatile ("sgdt %0"::"m" (gdtb)); asm volatile ("sgdt %0"::"m" (gdtb));
value32 = gdtb.limit; value32 = gdtb.limit;
if ((gdtb.base >> 47) & 0x1) if (((gdtb.base >> 47) & 0x1) != 0U)
gdtb.base |= 0xffff000000000000ull; gdtb.base |= 0xffff000000000000ull;
/* Set up the guest and host GDTB base fields with current GDTB base */ /* 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 ? */ /* TODO: Should guest TR point to host TR ? */
trbase = gdtb.base + tr_sel; trbase = gdtb.base + tr_sel;
if ((trbase >> 47) & 0x1) if (((trbase >> 47) & 0x1) != 0U)
trbase |= 0xffff000000000000ull; trbase |= 0xffff000000000000ull;
/* SS segment override */ /* SS segment override */
@ -989,7 +989,7 @@ static void init_host_state(__unused struct vcpu *vcpu)
/* Obtain the current interrupt descriptor table base */ /* Obtain the current interrupt descriptor table base */
asm volatile ("sidt %0"::"m" (idtb)); asm volatile ("sidt %0"::"m" (idtb));
/* base */ /* base */
if ((idtb.base >> 47) & 0x1) if (((idtb.base >> 47) & 0x1) != 0U)
idtb.base |= 0xffff000000000000ull; idtb.base |= 0xffff000000000000ull;
field = VMX_HOST_IDTR_BASE; field = VMX_HOST_IDTR_BASE;
@ -1144,7 +1144,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
VMX_PROCBASED_CTLS2_RDTSCP | VMX_PROCBASED_CTLS2_RDTSCP |
VMX_PROCBASED_CTLS2_UNRESTRICT); VMX_PROCBASED_CTLS2_UNRESTRICT);
if (vcpu->arch_vcpu.vpid) if (vcpu->arch_vcpu.vpid != 0)
value32 |= VMX_PROCBASED_CTLS2_VPID; value32 |= VMX_PROCBASED_CTLS2_VPID;
else else
value32 &= ~VMX_PROCBASED_CTLS2_VPID; value32 &= ~VMX_PROCBASED_CTLS2_VPID;
@ -1201,7 +1201,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
} }
/* Check for EPT support */ /* Check for EPT support */
if (is_ept_supported()) if (is_ept_supported() != 0)
pr_dbg("EPT is supported"); pr_dbg("EPT is supported");
else else
pr_err("Error: EPT is not supported"); pr_err("Error: EPT is not supported");

View File

@ -175,7 +175,7 @@ static int register_hrhd_units(void)
struct dmar_drhd_rt *drhd_rt; struct dmar_drhd_rt *drhd_rt;
uint32_t i; uint32_t i;
if (!info) { if (info == NULL) {
pr_warn("vtd: no dmar units found"); pr_warn("vtd: no dmar units found");
return -1; return -1;
} }
@ -232,7 +232,7 @@ static void iommu_flush_cache(struct dmar_drhd_rt *dmar_uint,
uint32_t i; uint32_t i;
/* if vtd support page-walk coherency, no need to flush cacheline */ /* 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; return;
for (i = 0; i < size; i += CACHE_LINE_SIZE) 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); uint8_t sgaw = iommu_cap_sagaw(dmar_uint->cap);
for (i = 4; i >= 0; i--) { for (i = 4; i >= 0; i--) {
if ((1 << i) & sgaw) if (((1 << i) & sgaw) != 0)
break; break;
} }
return (uint8_t)i; 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); iommu_write32(dmar_uint, DMAR_GCMD_REG, dmar_uint->gcmd);
/* 32-bit register */ /* 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); 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); iommu_write32(dmar_uint, DMAR_GCMD_REG, dmar_uint->gcmd);
/* 32-bit register */ /* 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); 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 * How to guarantee it when EPT is used as second-level
* translation paging structures? * translation paging structures?
*/ */
if (!iommu_ecap_sc(dmar_uint->ecap)) if (iommu_ecap_sc(dmar_uint->ecap) == 0U)
dev_dbg(ACRN_DBG_IOMMU, dev_dbg(ACRN_DBG_IOMMU,
"dmar uint doesn't support snoop control!"); "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; max_domain_id = dmar_uint->max_domain_id;
/* register operation is considered serial, no lock here */ /* 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); list_add_tail(&dmar_uint->list, &dmar_drhd_units);
else else
list_add(&dmar_uint->list, &dmar_drhd_units); list_add(&dmar_uint->list, &dmar_drhd_units);
dmar_hdrh_unit_count++; dmar_hdrh_unit_count++;
if (dmar_uint->gcmd & DMA_GCMD_TE) if ((dmar_uint->gcmd & DMA_GCMD_TE) != 0)
dmar_disable_translation(dmar_uint); 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 /* has the same segment number and
* the dmar unit has INCLUDE_PCI_ALL set * 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; return dmar_uint;
} }
@ -519,7 +519,7 @@ static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint)
{ {
uint32_t status; uint32_t status;
if (!iommu_cap_rwbf(dmar_uint->cap)) if (iommu_cap_rwbf(dmar_uint->cap) == 0U)
return; return;
IOMMU_LOCK(dmar_uint); 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); dmar_uint->gcmd | DMA_GCMD_WBF);
/* read lower 32 bits to check */ /* 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); 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_LOCK(dmar_uint);
iommu_write64(dmar_uint, DMAR_CCMD_REG, cmd); iommu_write64(dmar_uint, DMAR_CCMD_REG, cmd);
/* read upper 32bits to check */ /* 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); status);
IOMMU_UNLOCK(dmar_uint); IOMMU_UNLOCK(dmar_uint);
@ -605,16 +605,16 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
return; return;
} }
IOMMU_LOCK(dmar_uint); 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, addr);
iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset + 8, cmd); iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset + 8, cmd);
/* read upper 32bits to check */ /* read upper 32bits to check */
DMAR_WAIT_COMPLETION(dmar_uint->ecap_iotlb_offset + 12, 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); 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", pr_err("fail to invalidate IOTLB!, 0x%x, 0x%x",
status, iommu_read32(dmar_uint, DMAR_FSTS_REG)); 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); dmar_uint->gcmd | DMA_GCMD_SRTP);
/* 32-bit register */ /* 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); 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) 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; return;
/* currently skip PASID related parsing */ /* currently skip PASID related parsing */
pr_info("%s, Reason: 0x%x, SID: %x.%x.%x @0x%llx", 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_FR(high),
DMA_FRCD_UP_SID(high) >> 8, DMA_FRCD_UP_SID(high) >> 8,
(DMA_FRCD_UP_SID(high) >> 3) & 0x1f, (DMA_FRCD_UP_SID(high) >> 3) & 0x1f,
@ -749,7 +749,7 @@ static int dmar_fault_handler(int irq, void *data)
fault_status_analysis(fsr); fault_status_analysis(fsr);
#endif #endif
while (DMA_FSTS_PPF(fsr)) { while (DMA_FSTS_PPF(fsr) != 0U) {
loop++; loop++;
index = DMA_FSTS_FRI(fsr); index = DMA_FSTS_FRI(fsr);
record_reg_offset = dmar_uint->cap_fault_reg_offset 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; 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__); dev_dbg(ACRN_DBG_IOMMU, "%s: irq already setup", __func__);
return 0; return 0;
} }
@ -802,7 +802,7 @@ static int dmar_setup_interrupt(struct dmar_drhd_rt *dmar_uint)
dmar_uint, true, false, dmar_uint, true, false,
"dmar_fault_event"); "dmar_fault_event");
if (!dmar_uint->dmar_irq_node) { if (dmar_uint->dmar_irq_node == NULL) {
pr_err("%s: fail to setup interrupt", __func__); pr_err("%s: fail to setup interrupt", __func__);
return 1; 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) 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_disable_translation(dmar_uint);
dmar_fault_event_mask(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 */ /* TODO: check if a domain with the vm_id exists */
if (!translation_table) { if (translation_table == 0) {
pr_err("translation table is NULL"); pr_err("translation table is NULL");
return 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) int destroy_iommu_domain(struct iommu_domain *domain)
{ {
if (!domain) if (domain == NULL)
return 1; return 1;
/* currently only support ept */ /* 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 upper = 0;
uint64_t lower = 0; uint64_t lower = 0;
if (!domain) if (domain == NULL)
return 1; return 1;
dmar_uint = device_to_dmaru(segment, bus, devfun); 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", pr_err("no dmar unit found for device:0x%x:%x.%x",
bus, devfun >> 3, devfun & 0x7); bus, devfun >> 3, devfun & 0x7);
return 1; 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) { if (dmar_uint->root_table_addr == 0) {
void *root_table_vaddr = alloc_paging_struct(); 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); dmar_uint->root_table_addr = HVA2HPA(root_table_vaddr);
} else { } else {
ASSERT(0, "failed to allocate root table!"); ASSERT(false, "failed to allocate root table!");
return 1; 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]; 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(); void *vaddr = alloc_paging_struct();
if (vaddr) { if (vaddr != NULL) {
/* create context table for the bus if not present */ /* create context table for the bus if not present */
context_table_addr = HVA2HPA(vaddr); 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, iommu_flush_cache(dmar_uint, root_entry,
sizeof(struct dmar_root_entry)); sizeof(struct dmar_root_entry));
} else { } else {
ASSERT(0, "failed to allocate context table!"); ASSERT(false, "failed to allocate context table!");
return 1; return 1;
} }
} else { } 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]; context_entry = (struct dmar_context_entry *)&context_table[devfun * 2];
/* the context entry should not be present */ /* 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) ", pr_err("%s: context entry@0x%llx (Lower:%x) ",
__func__, context_entry, context_entry->lower); __func__, context_entry, context_entry->lower);
pr_err("already present for %x:%x.%x", 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; upper = 0;
lower = 0; lower = 0;
if (domain->is_host) { 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 /* When the Translation-type (T) field indicates
* pass-through processing (10b), AW field must be * pass-through processing (10b), AW field must be
* programmed to indicate the largest AGAW value * 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_root_entry *root_entry;
struct dmar_context_entry *context_entry; struct dmar_context_entry *context_entry;
if (!domain) if (domain == NULL)
return 1; return 1;
dmar_uint = device_to_dmaru(segment, bus, devfun); 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", pr_err("no dmar unit found for device:0x%x:%x",
bus, devfun); bus, devfun);
return 1; 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, int assign_iommu_device(struct iommu_domain *domain, uint8_t bus,
uint8_t devfun) uint8_t devfun)
{ {
if (!domain) if (domain == NULL)
return 1; return 1;
/* TODO: check if the device assigned */ /* 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, int unassign_iommu_device(struct iommu_domain *domain, uint8_t bus,
uint8_t devfun) uint8_t devfun)
{ {
if (!domain) if (domain == NULL)
return 1; return 1;
/* TODO: check if the device assigned */ /* TODO: check if the device assigned */
@ -1223,7 +1223,7 @@ int init_iommu(void)
spinlock_init(&domain_lock); spinlock_init(&domain_lock);
if (register_hrhd_units()) if (register_hrhd_units() != 0)
return -1; return -1;
host_domain = create_host_domain(); host_domain = create_host_domain();

View File

@ -114,8 +114,8 @@ biosacpi_search_rsdp(char *base, int length)
rsdp = (struct acpi_table_rsdp *)(base + ofs); rsdp = (struct acpi_table_rsdp *)(base + ofs);
/* compare signature, validate checksum */ /* compare signature, validate checksum */
if (!strncmp(rsdp->signature, ACPI_SIG_RSDP, if (strncmp(rsdp->signature, ACPI_SIG_RSDP,
strnlen_s(ACPI_SIG_RSDP, 8))) { strnlen_s(ACPI_SIG_RSDP, 8)) == 0) {
cp = (uint8_t *)rsdp; cp = (uint8_t *)rsdp;
sum = 0; sum = 0;
for (idx = 0; idx < RSDP_CHECKSUM_LENGTH; idx++) 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; 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 * AcpiOsGetRootPointer only verifies the checksum for
* the version 1.0 portion of the RSDP. Version 2.0 has * 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); sizeof(uint64_t);
for (i = 0; i < count; i++) { 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]; addr = xsdt->table_offset_entry[i];
break; break;
} }
@ -205,7 +205,7 @@ void *get_acpi_tbl(char *sig)
sizeof(uint32_t); sizeof(uint32_t);
for (i = 0; i < count; i++) { 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]; addr = rsdt->table_offset_entry[i];
break; break;
} }
@ -235,7 +235,7 @@ static int _parse_madt(void *madt, uint8_t *lapic_id_base)
if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) { if (entry->type == ACPI_MADT_TYPE_LOCAL_APIC) {
processor = (struct acpi_madt_local_apic *)entry; 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; *lapic_id_base++ = processor->id;
pcpu_id++; pcpu_id++;
} }

View File

@ -42,7 +42,7 @@ static void parse_other_modules(struct vm *vm,
start++; start++;
end = start; end = start;
while (*end != ' ' && *end) while (*end != ' ' && (*end) != 0)
end++; end++;
type_len = end - start; 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); dev_dbg(ACRN_DBG_BOOT, "fw-%d: %s", i, dyn_bootargs);
/*copy boot args to load addr, set src=load addr*/ /*copy boot args to load addr, set src=load addr*/
if (copy_once) { if (copy_once != 0) {
copy_once = 0; copy_once = 0;
strcpy_s(load_addr, MEM_2K, strcpy_s(load_addr, MEM_2K,
vm->sw.linux_info.bootargs_src_addr); vm->sw.linux_info.bootargs_src_addr);
@ -95,7 +95,7 @@ static void *get_kernel_load_addr(void *kernel_src_addr)
* non-relocatable. * non-relocatable.
*/ */
zeropage = (struct zero_page *)kernel_src_addr; 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 (void *)zeropage->hdr.pref_addr;
return kernel_src_addr; return kernel_src_addr;
@ -112,15 +112,15 @@ int init_vm0_boot_info(struct vm *vm)
} }
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) { if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
ASSERT(0, "no multiboot info found"); ASSERT(false, "no multiboot info found");
return -EINVAL; return -EINVAL;
} }
mbi = (struct multiboot_info *)((uint64_t)boot_regs[1]); mbi = (struct multiboot_info *)((uint64_t)boot_regs[1]);
dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags); dev_dbg(ACRN_DBG_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags);
if (!(mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS)) { if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
ASSERT(0, "no sos kernel info found"); ASSERT(false, "no sos kernel info found");
return -EINVAL; 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 * If there is cmdline from mbi->mi_cmdline, merge it with
* mods[0].mm_string * 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; char *cmd_src, *cmd_dst;
int off = 0; int off = 0;

View File

@ -170,7 +170,7 @@ again:
continue; 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) (mmap[j-1].mm_base_addr + mmap[j-1].mm_length)
== d->PhysicalStart) { == d->PhysicalStart) {
mmap[j-1].mm_length += d->NumberOfPages << EFI_PAGE_SHIFT; mmap[j-1].mm_length += d->NumberOfPages << EFI_PAGE_SHIFT;
@ -247,7 +247,7 @@ switch_to_guest_mode(EFI_HANDLE image)
config_table++; config_table++;
} }
if (!rsdp) { if (rsdp == NULL) {
Print(L"unable to find RSDP\n"); Print(L"unable to find RSDP\n");
goto out; goto out;
} }

View File

@ -39,9 +39,9 @@ void efi_spurious_handler(int vector)
return; return;
vcpu = per_cpu(vcpu, 0); 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); ret = vlapic_set_intr(vcpu, vector, 0);
if (ret) if (ret != 0)
pr_err("%s vlapic set intr fail, interrupt lost\n", pr_err("%s vlapic set intr fail, interrupt lost\n",
__func__); __func__);
} else } else

View File

@ -79,7 +79,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
for (bit_idx = ffz64(pool->bitmap[idx]); for (bit_idx = ffz64(pool->bitmap[idx]);
bit_idx < BITMAP_WORD_SIZE; bit_idx++) { bit_idx < BITMAP_WORD_SIZE; bit_idx++) {
/* Check if selected buffer is free */ /* Check if selected buffer is free */
if (pool->bitmap[idx] & (1 << bit_idx)) if ((pool->bitmap[idx] & (1 << bit_idx)) != 0U)
continue; continue;
/* Declare temporary variables to be used locally in /* 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 */ /* 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; break;
} }
@ -201,13 +201,13 @@ static void deallocate_mem(struct mem_pool *pool, void *ptr)
contiguity_bitmask = &pool->contiguity_bitmap[bmp_idx]; contiguity_bitmask = &pool->contiguity_bitmap[bmp_idx];
/* Mark the buffer as free */ /* Mark the buffer as free */
if (*bitmask & (1 << bit_idx)) if ((*bitmask & (1 << bit_idx)) != 0U)
*bitmask ^= (1 << bit_idx); *bitmask ^= (1 << bit_idx);
else else
break; break;
/* Reset the Contiguity bit of buffer */ /* Reset the Contiguity bit of buffer */
if (*contiguity_bitmask & (1 << bit_idx)) if ((*contiguity_bitmask & (1 << bit_idx)) != 0U)
*contiguity_bitmask ^= (1 << bit_idx); *contiguity_bitmask ^= (1 << bit_idx);
else else
break; break;
@ -362,7 +362,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
/*small data block*/ /*small data block*/
if (slen < 8) { if (slen < 8) {
while (slen) { while (slen != 0U) {
*dest8++ = *src8++; *dest8++ = *src8++;
slen--; 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.*/ /*make sure 8bytes-aligned for at least one addr.*/
if ((!MEM_ALIGNED_CHECK(src8, 8)) && (!MEM_ALIGNED_CHECK(dest8, 8))) { 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++; *dest8++ = *src8++;
} }
@ -389,7 +389,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
} }
/*tail bytes*/ /*tail bytes*/
while (slen) { while (slen != 0U) {
*dest8++ = *src8++; *dest8++ = *src8++;
slen--; slen--;
} }
@ -410,7 +410,7 @@ void *memset(void *base, uint8_t v, size_t n)
/*do the few bytes to get uint64_t alignment*/ /*do the few bytes to get uint64_t alignment*/
count = n; count = n;
for (; count && ((uint64_t)dest_p & 7); count--) for (; count != 0U && ((uint64_t)dest_p & 7) != 0U; count--)
*dest_p++ = v; *dest_p++ = v;
/*64-bit mode*/ /*64-bit mode*/

View File

@ -97,7 +97,7 @@ static const char *get_int(const char *s, int *x)
*x = *x * 10 + (*s++ - '0'); *x = *x * 10 + (*s++ - '0');
/* apply sign to result */ /* apply sign to result */
if (negative) if (negative != 0)
*x = -*x; *x = -*x;
return s; return s;
@ -118,7 +118,7 @@ static const char *get_flags(const char *s, int *flags)
const char *pos; const char *pos;
/* parse multiple flags */ /* parse multiple flags */
while (*s) { while ((*s) != 0) {
/* get index of flag. Terminate loop if no flag character was /* get index of flag. Terminate loop if no flag character was
* found * found
*/ */
@ -132,11 +132,11 @@ static const char *get_flags(const char *s, int *flags)
} }
/* Spec says that '-' has a higher priority than '0' */ /* 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; *flags &= ~PRINT_FLAG_PAD_ZERO;
/* Spec says that '+' has a higher priority than ' ' */ /* Spec says that '+' has a higher priority than ' ' */
if (*flags & PRINT_FLAG_SIGN) if ((*flags & PRINT_FLAG_SIGN) != 0)
*flags &= ~PRINT_FLAG_SPACE; *flags &= ~PRINT_FLAG_SPACE;
return s; return s;
@ -203,14 +203,14 @@ static int format_number(struct print_param *param)
* used for padding, the prefix is emitted after the padding. * 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 */ /* use '0' for padding */
pad = '0'; pad = '0';
/* emit prefix, return early if an error occurred */ /* emit prefix, return early if an error occurred */
res = param->emit(PRINT_CMD_COPY, param->vars.prefix, res = param->emit(PRINT_CMD_COPY, param->vars.prefix,
param->vars.prefixlen, param->data); param->vars.prefixlen, param->data);
if (param->vars.prefix && (res < 0)) if ((param->vars.prefix != NULL) && (res < 0))
return res; return res;
/* invalidate prefix */ /* 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 */ /* emit prefix (if any), return early in case of an error */
res = param->emit(PRINT_CMD_COPY, param->vars.prefix, res = param->emit(PRINT_CMD_COPY, param->vars.prefix,
param->vars.prefixlen, param->data); param->vars.prefixlen, param->data);
if (param->vars.prefix && (res < 0)) if ((param->vars.prefix != NULL) && (res < 0))
return res; return res;
/* insert additional 0's for precision, return early if an error /* 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; mask = (1ULL << shift) - 1;
/* determine digit translation table */ /* 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; upper_hex_digits : lower_hex_digits;
/* apply mask for short/char */ /* apply mask for short/char */
v &= param->vars.mask; v &= param->vars.mask;
/* determine prefix for alternate form */ /* 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'; prefix[0] = '0';
param->vars.prefix = prefix; param->vars.prefix = prefix;
param->vars.prefixlen = 1; param->vars.prefixlen = 1;
@ -297,7 +297,7 @@ static int print_pow2(struct print_param *param,
/* determine digits from right to left */ /* determine digits from right to left */
do { do {
*--pos = digits[(v & mask)]; *--pos = digits[(v & mask)];
} while (v >>= shift); } while ((v >>= shift) != 0);
/* assign parameter and apply width and precision */ /* assign parameter and apply width and precision */
param->vars.value = pos; 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 */ /* determine sign if explicit requested in the format string */
if (!param->vars.prefix) { if (param->vars.prefix == NULL) {
if (param->vars.flags & PRINT_FLAG_SIGN) { if ((param->vars.flags & PRINT_FLAG_SIGN) != 0) {
param->vars.prefix = "+"; param->vars.prefix = "+";
param->vars.prefixlen = 1; 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.prefix = " ";
param->vars.prefixlen = 1; 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 /* we need the length of the string if either width or precision is
* given * 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); len = strnlen_s(s, PRINT_STRING_MAX_LEN);
/* precision gives the max. number of characters to emit. */ /* 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; len = param->vars.precision;
/* calculate the number of additional characters to get the required /* 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 /* emit additional characters on the right, return early if an error
* occurred * 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); res = param->emit(PRINT_CMD_FILL, " ", w, param->data);
if (res < 0) if (res < 0)
return res; return res;
@ -446,11 +446,11 @@ int do_print(const char *fmt, struct print_param *param,
const char *start; const char *start;
/* main loop: analyse until there are no more characters */ /* main loop: analyse until there are no more characters */
while (*fmt) { while ((*fmt) != 0) {
/* mark the current position and search the next '%' */ /* mark the current position and search the next '%' */
start = fmt; start = fmt;
while (*fmt && (*fmt != '%')) while (((*fmt) != 0) && (*fmt != '%'))
fmt++; fmt++;
/* /*
@ -500,8 +500,8 @@ int do_print(const char *fmt, struct print_param *param,
/* decimal number */ /* decimal number */
else if ((ch == 'd') || (ch == 'i')) { else if ((ch == 'd') || (ch == 'i')) {
res = print_decimal(param, res = print_decimal(param,
(param->vars.flags & ((param->vars.flags &
PRINT_FLAG_LONG_LONG) ? PRINT_FLAG_LONG_LONG) != 0) ?
__builtin_va_arg(args, __builtin_va_arg(args,
long long) long long)
: (long long) : (long long)
@ -512,8 +512,8 @@ int do_print(const char *fmt, struct print_param *param,
else if (ch == 'u') { else if (ch == 'u') {
param->vars.flags |= PRINT_FLAG_UINT32; param->vars.flags |= PRINT_FLAG_UINT32;
res = print_decimal(param, res = print_decimal(param,
(param->vars.flags & ((param->vars.flags &
PRINT_FLAG_LONG_LONG) ? PRINT_FLAG_LONG_LONG) != 0) ?
__builtin_va_arg(args, __builtin_va_arg(args,
unsigned long long) unsigned long long)
: (unsigned long long) : (unsigned long long)
@ -523,8 +523,8 @@ int do_print(const char *fmt, struct print_param *param,
/* octal number */ /* octal number */
else if (ch == 'o') { else if (ch == 'o') {
res = print_pow2(param, res = print_pow2(param,
(param->vars.flags & ((param->vars.flags &
PRINT_FLAG_LONG_LONG) ? PRINT_FLAG_LONG_LONG) != 0) ?
__builtin_va_arg(args, __builtin_va_arg(args,
unsigned long long) unsigned long long)
: (unsigned long long) : (unsigned long long)
@ -537,8 +537,8 @@ int do_print(const char *fmt, struct print_param *param,
if (ch == 'X') if (ch == 'X')
param->vars.flags |= PRINT_FLAG_UPPER; param->vars.flags |= PRINT_FLAG_UPPER;
res = print_pow2(param, res = print_pow2(param,
(param->vars.flags & ((param->vars.flags &
PRINT_FLAG_LONG_LONG) ? PRINT_FLAG_LONG_LONG) != 0) ?
__builtin_va_arg(args, __builtin_va_arg(args,
unsigned long long) unsigned long long)
: (unsigned long long) : (unsigned long long)
@ -599,7 +599,7 @@ static int charmem(int cmd, const char *s, int sz, void *hnd)
/* copy mode ? */ /* copy mode ? */
if (cmd == PRINT_CMD_COPY) { if (cmd == PRINT_CMD_COPY) {
if (sz < 0) { if (sz < 0) {
while (*s) { while ((*s) != 0) {
if (n < param->sz - param->wrtn) if (n < param->sz - param->wrtn)
*p = *s; *p = *s;
p++; p++;
@ -608,7 +608,7 @@ static int charmem(int cmd, const char *s, int sz, void *hnd)
} }
} else if (sz > 0) { } else if (sz > 0) {
while (*s && n < sz) { while (((*s) != 0) && n < sz) {
if (n < param->sz - param->wrtn) if (n < param->sz - param->wrtn)
*p = *s; *p = *s;
p++; p++;
@ -636,7 +636,7 @@ int vsnprintf(char *dst, int sz, const char *fmt, va_list args)
/* the result of this function */ /* the result of this function */
int res = 0; int res = 0;
if (sz <= 0 || !dst) { if (sz <= 0 || (dst == NULL)) {
dst = c; dst = c;
sz = 1; sz = 1;
} }

View File

@ -222,7 +222,7 @@ strtol(const char *nptr, char **endptr, register int base)
*/ */
do { do {
c = *s++; c = *s++;
} while (ISSPACE(c)); } while (ISSPACE(c) != 0U);
if (c == '-') { if (c == '-') {
neg = 1; neg = 1;
c = *s++; 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 * Set any if any `digits' consumed; make it negative to indicate
* overflow. * overflow.
*/ */
cutoff = neg ? -(uint64_t)LONG_MIN : LONG_MAX; cutoff = (neg != 0) ? -(uint64_t)LONG_MIN : LONG_MAX;
cutlim = cutoff % (uint64_t)base; cutlim = cutoff % (uint64_t)base;
cutoff /= (uint64_t)base; cutoff /= (uint64_t)base;
for (acc = 0, any = 0;; c = *s++) { for (acc = 0, any = 0;; c = *s++) {
if (ISDIGIT(c)) if (ISDIGIT(c) != 0U)
c -= '0'; c -= '0';
else if (ISALPHA(c)) else if (ISALPHA(c) != 0U)
c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; c -= (ISUPPER(c) != 0U) ? 'A' - 10 : 'a' - 10;
else else
break; break;
if (c >= base) if (c >= base)
@ -275,11 +275,11 @@ strtol(const char *nptr, char **endptr, register int base)
} }
} }
if (any < 0) if (any < 0)
acc = neg ? LONG_MIN : LONG_MAX; acc = (neg != 0) ? LONG_MIN : LONG_MAX;
else if (neg) else if (neg != 0)
acc = -acc; acc = -acc;
if (endptr != NULL) if (endptr != NULL)
*endptr = (char *) (any ? s - 1 : nptr); *endptr = (char *) ((any != 0) ? s - 1 : nptr);
return acc; return acc;
} }
@ -303,7 +303,7 @@ strtoul(const char *nptr, char **endptr, register int base)
*/ */
do { do {
c = *s++; c = *s++;
} while (ISSPACE(c)); } while (ISSPACE(c) != 0U);
if (c == '-') { if (c == '-') {
neg = 1; neg = 1;
c = *s++; c = *s++;
@ -320,10 +320,10 @@ strtoul(const char *nptr, char **endptr, register int base)
cutoff = (uint64_t)ULONG_MAX / (uint64_t)base; cutoff = (uint64_t)ULONG_MAX / (uint64_t)base;
cutlim = (uint64_t)ULONG_MAX % (uint64_t)base; cutlim = (uint64_t)ULONG_MAX % (uint64_t)base;
for (acc = 0, any = 0;; c = *s++) { for (acc = 0, any = 0;; c = *s++) {
if (ISDIGIT(c)) if (ISDIGIT(c) != 0U)
c -= '0'; c -= '0';
else if (ISALPHA(c)) else if (ISALPHA(c) != 0U)
c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; c -= (ISUPPER(c) != 0U) ? 'A' - 10 : 'a' - 10;
else else
break; break;
if (c >= base) if (c >= base)
@ -338,10 +338,10 @@ strtoul(const char *nptr, char **endptr, register int base)
} }
if (any < 0) if (any < 0)
acc = ULONG_MAX; acc = ULONG_MAX;
else if (neg) else if (neg != 0)
acc = -acc; acc = -acc;
if (endptr != NULL) if (endptr != NULL)
*endptr = (char *) (any ? s - 1 : nptr); *endptr = (char *) ((any != 0) ? s - 1 : nptr);
return acc; return acc;
} }
@ -353,10 +353,10 @@ atoi(const char *str)
char *strchr(const char *s, int ch) char *strchr(const char *s, int ch)
{ {
while (*s && (*s != ch)) while ((*s != 0) && (*s != ch))
++s; ++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; return 0;
count = 0; count = 0;
while (*str) { while ((*str) != 0) {
if (maxlen == 0) if (maxlen == 0)
break; break;
@ -563,7 +563,7 @@ char hexdigit(int decimal_val)
int strcmp(const char *s1, const char *s2) int strcmp(const char *s1, const char *s2)
{ {
while (*s1 && *s2 && *s1 == *s2) { while (((*s1) != 0) && ((*s2) != 0) && ((*s1) == (*s2))) {
s1++; s1++;
s2++; s2++;
} }
@ -573,7 +573,7 @@ int strcmp(const char *s1, const char *s2)
int strncmp(const char *s1, const char *s2, size_t n) 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++; s1++;
s2++; s2++;
n--; n--;