Skip to content

Commit 10c64a5

Browse files
shiqinggwenlingz
authored andcommitted
hv: fix MISRA-C issues related to for loop
This patch fixes the following issues: - Assignment operation in expression. - For loop incrementation is not simple. - No brackets to loop body. - Use of comma operator. v1 -> v2: * Replace &x->y with &(x->y) based on our new coding rule Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent 852f613 commit 10c64a5

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

hypervisor/arch/x86/guest/pm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ register_gas_io_handler(struct vm *vm, struct acpi_generic_address *gas)
202202
return;
203203
}
204204

205-
gas_io.flags = IO_ATTR_RW,
206-
gas_io.base = (uint16_t)gas->address,
205+
gas_io.flags = IO_ATTR_RW;
206+
gas_io.base = (uint16_t)gas->address;
207207
gas_io.len = io_len[gas->access_size];
208208

209209
register_io_emulation_handler(vm, &gas_io,

hypervisor/arch/x86/notify.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ void smp_call_function(uint64_t mask, smp_call_func_t func, void *data)
3535

3636
/* wait for previous smp call complete, which may run on other cpus */
3737
while (atomic_cmpxchg64(&smp_call_mask, 0UL, mask & INVALID_BIT_INDEX));
38-
while ((pcpu_id = ffs64(mask)) != INVALID_BIT_INDEX) {
38+
pcpu_id = ffs64(mask);
39+
while (pcpu_id != INVALID_BIT_INDEX) {
3940
bitmap_clear_nolock(pcpu_id, &mask);
4041
if (bitmap_test(pcpu_id, &pcpu_active_bitmap)) {
4142
smp_call = &per_cpu(smp_call_info, pcpu_id);
@@ -46,6 +47,7 @@ void smp_call_function(uint64_t mask, smp_call_func_t func, void *data)
4647
pr_err("pcpu_id %d not in active!", pcpu_id);
4748
bitmap_clear_nolock(pcpu_id, &smp_call_mask);
4849
}
50+
pcpu_id = ffs64(mask);
4951
}
5052
send_dest_ipi(smp_call_mask, VECTOR_NOTIFY_VCPU,
5153
INTR_LAPIC_ICR_LOGICAL);

hypervisor/arch/x86/pagetable.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ int mmu_modify_or_del(uint64_t *pml4_page,
264264
dev_dbg(ACRN_DBG_MMU, "%s, vaddr: 0x%llx, size: 0x%llx\n",
265265
__func__, vaddr, size);
266266
vaddr_end = vaddr + size;
267-
for (; vaddr < vaddr_end; vaddr = vaddr_next) {
267+
while (vaddr < vaddr_end) {
268268
vaddr_next = (vaddr & PML4E_MASK) + PML4E_SIZE;
269269
pml4e = pml4e_offset(pml4_page, vaddr);
270270
if (pgentry_present(ptt, *pml4e) == 0UL) {
@@ -276,6 +276,8 @@ int mmu_modify_or_del(uint64_t *pml4_page,
276276
if (ret != 0) {
277277
return ret;
278278
}
279+
280+
vaddr = vaddr_next;
279281
}
280282

281283
return 0;
@@ -434,7 +436,7 @@ int mmu_add(uint64_t *pml4_page, uint64_t paddr_base,
434436
paddr = ROUND_PAGE_UP(paddr_base);
435437
vaddr_end = vaddr + ROUND_PAGE_DOWN(size);
436438

437-
for (; vaddr < vaddr_end; vaddr = vaddr_next) {
439+
while (vaddr < vaddr_end) {
438440
vaddr_next = (vaddr & PML4E_MASK) + PML4E_SIZE;
439441
pml4e = pml4e_offset(pml4_page, vaddr);
440442
if (pgentry_present(ptt, *pml4e) == 0UL) {
@@ -449,6 +451,7 @@ int mmu_add(uint64_t *pml4_page, uint64_t paddr_base,
449451
}
450452

451453
paddr += (vaddr_next - vaddr);
454+
vaddr = vaddr_next;
452455
}
453456

454457
return 0;

hypervisor/arch/x86/vmx.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,10 @@ static void init_guest_context_real(struct vcpu *vcpu)
547547
{
548548
struct ext_context *ectx =
549549
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].ext_ctx;
550+
struct segment_sel *seg;
550551

551552
/* cs, ss, ds, es, fs, gs; cs will be override later. */
552-
for(struct segment_sel *seg = &ectx->cs; seg <= &ectx->gs; seg++) {
553+
for (seg = &(ectx->cs); seg <= &(ectx->gs); seg++) {
553554
seg->selector = 0U;
554555
seg->base = 0UL;
555556
seg->limit = 0xFFFFU;
@@ -606,15 +607,15 @@ static void init_guest_context_vm0_bsp(struct vcpu *vcpu)
606607
struct ext_context *ectx =
607608
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].ext_ctx;
608609
struct boot_ctx * init_ctx = (struct boot_ctx *)(&vm0_boot_context);
609-
uint16_t *sel;
610+
uint16_t *sel = &(init_ctx->cs_sel);
610611
struct segment_sel *seg;
611612

612-
for(seg = &ectx->cs, sel = &init_ctx->cs_sel;
613-
seg <= &ectx->gs; seg ++, sel++) {
613+
for (seg = &(ectx->cs); seg <= &(ectx->gs); seg++) {
614614
seg->base = 0UL;
615615
seg->limit = 0xFFFFFFFFU;
616616
seg->attr = PROTECTED_MODE_DATA_SEG_AR;
617617
seg->selector = *sel;
618+
sel++;
618619
}
619620
ectx->cs.attr = init_ctx->cs_ar; /* override cs attr */
620621

@@ -644,7 +645,7 @@ static void init_guest_context_protect(struct vcpu *vcpu)
644645
struct segment_sel *seg;
645646

646647
ectx->gdtr.base = create_guest_init_gdt(vcpu->vm, &ectx->gdtr.limit);
647-
for(seg = &ectx->cs; seg <= &ectx->gs; seg ++) {
648+
for (seg = &(ectx->cs); seg <= &(ectx->gs); seg++) {
648649
seg->base = 0UL;
649650
seg->limit = 0xFFFFFFFFU;
650651
seg->attr = PROTECTED_MODE_DATA_SEG_AR;
@@ -721,7 +722,7 @@ static void init_guest_state(struct vcpu *vcpu)
721722
ctx->ext_ctx.tr.limit = 0xFFFFU;
722723
ctx->ext_ctx.tr.attr = TR_AR;
723724

724-
if(vcpu_mode == CPU_MODE_REAL) {
725+
if (vcpu_mode == CPU_MODE_REAL) {
725726
init_guest_context_real(vcpu);
726727
init_guest_vmx(vcpu, CR0_ET | CR0_NE, 0, 0);
727728
} else if (is_vm0(vcpu->vm) && is_vcpu_bsp(vcpu)) {

hypervisor/boot/reloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ static void update_trampoline_code_refs(uint64_t dest_pa)
184184
*(uint64_t *)(ptr) += dest_pa;
185185

186186
ptr = HPA2HVA(dest_pa + trampoline_relo_addr(&trampoline_pdpt_addr));
187-
for (i = 0; i < 4; i++)
187+
for (i = 0; i < 4; i++) {
188188
*(uint64_t *)(ptr + sizeof(uint64_t) * i) += dest_pa;
189+
}
189190

190191
/* update the gdt base pointer with relocated offset */
191192
ptr = HPA2HVA(dest_pa + trampoline_relo_addr(&trampoline_gdt_ptr));

hypervisor/common/vm_load.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ int load_guest(struct vm *vm, struct vcpu *vcpu)
9696
lowmem_gpa_top = *(uint64_t *)hva;
9797

9898
/* hardcode vcpu entry addr(kernel entry) & rsi (zeropage)*/
99-
for (i = 0; i < NUM_GPRS; i++)
99+
for (i = 0; i < NUM_GPRS; i++) {
100100
vcpu_set_gpreg(vcpu, i, 0UL);
101+
}
101102

102103
hva = GPA2HVA(vm, lowmem_gpa_top -
103104
MEM_4K - MEM_2K);
@@ -169,8 +170,9 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
169170
/* Documentation states: ebx=0, edi=0, ebp=0, esi=ptr to
170171
* zeropage
171172
*/
172-
for (i = 0; i < NUM_GPRS; i++)
173+
for (i = 0; i < NUM_GPRS; i++) {
173174
vcpu_set_gpreg(vcpu, i, 0UL);
175+
}
174176

175177
/* Get host-physical address for guest bootargs */
176178
hva = GPA2HVA(vm,

0 commit comments

Comments
 (0)