Skip to content

Commit e3ee9cf

Browse files
Shawnshhwenlingz
authored andcommitted
HV: fix expression is not boolean
MISRA-C standard requires the type of result of expression in if/while pattern shall be boolean. Tracked-On: #861 Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
1 parent 5cbda22 commit e3ee9cf

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

hypervisor/arch/x86/guest/pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static bool rt_vm_pm1a_io_write(struct acrn_vm *vm, uint16_t addr, size_t width,
249249
if (width != 2U) {
250250
pr_dbg("Invalid address (0x%x) or width (0x%x)", addr, width);
251251
} else {
252-
if (((v & VIRTUAL_PM1A_SLP_EN) && (((v & VIRTUAL_PM1A_SLP_TYP) >> 10U) == 5U)) != 0U) {
252+
if ((((v & VIRTUAL_PM1A_SLP_EN) != 0U) && (((v & VIRTUAL_PM1A_SLP_TYP) >> 10U) == 5U)) != 0U) {
253253
vm->state = VM_POWERING_OFF;
254254
}
255255
}

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline uint64_t vcpu_get_rip(struct acrn_vcpu *vcpu)
4141
struct run_context *ctx =
4242
&vcpu->arch.contexts[vcpu->arch.cur_context].run_ctx;
4343

44-
if (bitmap_test(CPU_REG_RIP, &vcpu->reg_updated) == 0 &&
44+
if (!bitmap_test(CPU_REG_RIP, &vcpu->reg_updated) &&
4545
bitmap_test_and_set_lock(CPU_REG_RIP, &vcpu->reg_cached) == 0)
4646
ctx->rip = exec_vmread(VMX_GUEST_RIP);
4747
return ctx->rip;
@@ -75,9 +75,10 @@ inline uint64_t vcpu_get_efer(struct acrn_vcpu *vcpu)
7575
struct run_context *ctx =
7676
&vcpu->arch.contexts[vcpu->arch.cur_context].run_ctx;
7777

78-
if (bitmap_test(CPU_REG_EFER, &vcpu->reg_updated) == 0 &&
79-
bitmap_test_and_set_lock(CPU_REG_EFER, &vcpu->reg_cached) == 0)
78+
if (!bitmap_test(CPU_REG_EFER, &vcpu->reg_updated) &&
79+
!bitmap_test_and_set_lock(CPU_REG_EFER, &vcpu->reg_cached)) {
8080
ctx->ia32_efer = exec_vmread64(VMX_GUEST_IA32_EFER_FULL);
81+
}
8182
return ctx->ia32_efer;
8283
}
8384

@@ -93,10 +94,11 @@ inline uint64_t vcpu_get_rflags(struct acrn_vcpu *vcpu)
9394
struct run_context *ctx =
9495
&vcpu->arch.contexts[vcpu->arch.cur_context].run_ctx;
9596

96-
if (bitmap_test(CPU_REG_RFLAGS, &vcpu->reg_updated) == 0 &&
97-
bitmap_test_and_set_lock(CPU_REG_RFLAGS,
98-
&vcpu->reg_cached) == 0 && vcpu->launched)
97+
if (!bitmap_test(CPU_REG_RFLAGS, &vcpu->reg_updated) &&
98+
!bitmap_test_and_set_lock(CPU_REG_RFLAGS,
99+
&vcpu->reg_cached) && vcpu->launched) {
99100
ctx->rflags = exec_vmread(VMX_GUEST_RFLAGS);
101+
}
100102
return ctx->rflags;
101103
}
102104

@@ -186,14 +188,14 @@ struct acrn_vcpu *get_ever_run_vcpu(uint16_t pcpu_id)
186188
static void set_vcpu_mode(struct acrn_vcpu *vcpu, uint32_t cs_attr, uint64_t ia32_efer,
187189
uint64_t cr0)
188190
{
189-
if (ia32_efer & MSR_IA32_EFER_LMA_BIT) {
190-
if (cs_attr & 0x2000U) {
191+
if ((ia32_efer & MSR_IA32_EFER_LMA_BIT) != 0UL) {
192+
if ((cs_attr & 0x2000U) != 0U) {
191193
/* CS.L = 1 */
192194
vcpu->arch.cpu_mode = CPU_MODE_64BIT;
193195
} else {
194196
vcpu->arch.cpu_mode = CPU_MODE_COMPATIBILITY;
195197
}
196-
} else if (cr0 & CR0_PE) {
198+
} else if ((cr0 & CR0_PE) != 0UL) {
197199
vcpu->arch.cpu_mode = CPU_MODE_PROTECTED;
198200
} else {
199201
vcpu->arch.cpu_mode = CPU_MODE_REAL;
@@ -216,7 +218,7 @@ void set_vcpu_regs(struct acrn_vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs)
216218
* If the set_vcpu_regs is used not only for vcpu state
217219
* initialization, this part of code needs be revised.
218220
*/
219-
if (vcpu_regs->cr0 & CR0_PE) {
221+
if ((vcpu_regs->cr0 & CR0_PE) != 0UL) {
220222
attr = PROTECTED_MODE_DATA_SEG_AR;
221223
limit = PROTECTED_MODE_SEG_LIMIT;
222224
} else {
@@ -451,7 +453,7 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu)
451453
pr_info("VM %d Starting VCPU %hu",
452454
vcpu->vm->vm_id, vcpu->vcpu_id);
453455

454-
if (vcpu->arch.vpid)
456+
if (vcpu->arch.vpid != 0U)
455457
exec_vmwrite16(VMX_VPID, vcpu->arch.vpid);
456458

457459
/*
@@ -518,10 +520,11 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu)
518520

519521
if (status != 0) {
520522
/* refer to 64-ia32 spec section 24.9.1 volume#3 */
521-
if (vcpu->arch.exit_reason & VMX_VMENTRY_FAIL)
523+
if ((vcpu->arch.exit_reason & VMX_VMENTRY_FAIL) != 0U) {
522524
pr_fatal("vmentry fail reason=%lx", vcpu->arch.exit_reason);
523-
else
525+
} else {
524526
pr_fatal("vmexit fail err_inst=%x", exec_vmread32(VMX_INSTR_ERROR));
527+
}
525528

526529
ASSERT(status == 0, "vm fail");
527530
}

hypervisor/boot/cmdline.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ int32_t parse_hv_cmdline(void)
2020
struct multiboot_info *mbi = NULL;
2121

2222
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
23-
ASSERT(0, "no multiboot info found");
2423
return -EINVAL;
2524
}
2625

2726
mbi = (struct multiboot_info *)(hpa2hva((uint64_t)boot_regs[1]));
2827
dev_dbg(ACRN_DBG_PARSE, "Multiboot detected, flag=0x%x", mbi->mi_flags);
2928

30-
if (!(mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE)) {
29+
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) == 0U) {
3130
dev_dbg(ACRN_DBG_PARSE, "no hv cmdline!");
3231
return -EINVAL;
3332
}
@@ -40,15 +39,15 @@ int32_t parse_hv_cmdline(void)
4039
start++;
4140

4241
end = start + 1;
43-
while (*end != ' ' && *end)
42+
while ((*end != ' ') && ((*end) != '\0'))
4443
end++;
4544

4645
if (!handle_dbg_cmd(start, end - start)) {
4746
/* if not handled by handle_dbg_cmd, it can be handled further */
4847
}
4948
start = end + 1;
5049

51-
} while (*end && *start);
50+
} while (((*end) != '\0') && ((*start) != '\0'));
5251

5352
return 0;
5453
}

hypervisor/debug/console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct acrn_vuart *vuart_console_active(void)
100100
}
101101
}
102102

103-
return (vu && vu->active) ? vu : NULL;
103+
return ((vu != NULL) && vu->active) ? vu : NULL;
104104
}
105105

106106
static void console_timer_callback(__unused void *data)

hypervisor/dm/vuart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static bool vuart_write(struct acrn_vm *vm, uint16_t offset_arg,
346346
offset -= vu->port_base;
347347
target_vu = vu->target_vu;
348348

349-
if (!(vu->mcr & MCR_LOOPBACK) &&
349+
if (((vu->mcr & MCR_LOOPBACK) == 0U) &&
350350
(offset == UART16550_THR) && (target_vu != NULL)) {
351351
send_to_target(target_vu, value_u8);
352352
} else {

0 commit comments

Comments
 (0)