Skip to content

Commit 277c7ec

Browse files
Shawnshhwenlingz
authored andcommitted
hv: hypercall: fix "Procedure has more than one exit point"
Misra C requires Function must have only 1 return entry. Fixed it by use "if ... else ..." format. Tracked-On: #861 Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 7016244 commit 277c7ec

File tree

1 file changed

+65
-71
lines changed

1 file changed

+65
-71
lines changed

hypervisor/common/hypercall.c

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,24 @@ int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid)
4343
{
4444
struct acrn_vcpu *vcpu;
4545
uint16_t i;
46+
int32_t ret = 0;
4647

4748
pr_info("sos offline cpu with lapicid %lld", lapicid);
4849

4950
foreach_vcpu(i, vm, vcpu) {
5051
if (vlapic_get_apicid(vcpu_vlapic(vcpu)) == lapicid) {
5152
/* should not offline BSP */
5253
if (vcpu->vcpu_id == BOOT_CPU_ID) {
53-
return -1;
54+
ret = -1;
55+
break;
5456
}
5557
pause_vcpu(vcpu, VCPU_ZOMBIE);
5658
reset_vcpu(vcpu);
5759
offline_vcpu(vcpu);
5860
}
5961
}
6062

61-
return 0;
63+
return ret;
6264
}
6365

6466
/**
@@ -113,28 +115,28 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
113115
struct vm_description vm_desc;
114116

115117
(void)memset((void *)&cv, 0U, sizeof(cv));
116-
if (copy_from_gpa(vm, &cv, param, sizeof(cv)) != 0) {
117-
pr_err("%s: Unable copy param to vm\n", __func__);
118-
return -1;
119-
}
120-
121-
(void)memset(&vm_desc, 0U, sizeof(vm_desc));
122-
vm_desc.sworld_supported = ((cv.vm_flag & (SECURE_WORLD_ENABLED)) != 0U);
123-
(void)memcpy_s(&vm_desc.GUID[0], 16U, &cv.GUID[0], 16U);
124-
ret = create_vm(&vm_desc, &target_vm);
118+
if (copy_from_gpa(vm, &cv, param, sizeof(cv)) == 0) {
119+
(void)memset(&vm_desc, 0U, sizeof(vm_desc));
120+
vm_desc.sworld_supported = ((cv.vm_flag & (SECURE_WORLD_ENABLED)) != 0U);
121+
(void)memcpy_s(&vm_desc.GUID[0], 16U, &cv.GUID[0], 16U);
122+
123+
ret = create_vm(&vm_desc, &target_vm);
124+
if (ret != 0) {
125+
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
126+
cv.vmid = ACRN_INVALID_VMID;
127+
ret = -1;
128+
} else {
129+
cv.vmid = target_vm->vm_id;
130+
ret = 0;
131+
}
125132

126-
if (ret != 0) {
127-
dev_dbg(ACRN_DBG_HYCALL, "HCALL: Create VM failed");
128-
cv.vmid = ACRN_INVALID_VMID;
129-
ret = -1;
133+
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
134+
pr_err("%s: Unable copy param to vm\n", __func__);
135+
ret = -1;
136+
}
130137
} else {
131-
cv.vmid = target_vm->vm_id;
132-
ret = 0;
133-
}
134-
135-
if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) {
136138
pr_err("%s: Unable copy param to vm\n", __func__);
137-
return -1;
139+
ret = -1;
138140
}
139141

140142
return ret;
@@ -240,22 +242,20 @@ int32_t hcall_create_vcpu(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
240242
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
241243

242244
if ((target_vm == NULL) || (param == 0U)) {
243-
return -1;
244-
}
245-
246-
if (copy_from_gpa(vm, &cv, param, sizeof(cv)) != 0) {
245+
ret = -1;
246+
} else if (copy_from_gpa(vm, &cv, param, sizeof(cv)) != 0) {
247247
pr_err("%s: Unable copy param to vm\n", __func__);
248-
return -1;
249-
}
250-
251-
pcpu_id = allocate_pcpu();
252-
if (pcpu_id == INVALID_CPU_ID) {
253-
pr_err("%s: No physical available\n", __func__);
254-
return -1;
248+
ret = -1;
249+
} else {
250+
pcpu_id = allocate_pcpu();
251+
if (pcpu_id == INVALID_CPU_ID) {
252+
pr_err("%s: No physical available\n", __func__);
253+
ret = -1;
254+
} else {
255+
ret = prepare_vcpu(target_vm, pcpu_id);
256+
}
255257
}
256258

257-
ret = prepare_vcpu(target_vm, pcpu_id);
258-
259259
return ret;
260260
}
261261

@@ -303,30 +303,24 @@ int32_t hcall_set_vcpu_regs(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
303303
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
304304
struct acrn_set_vcpu_regs vcpu_regs;
305305
struct acrn_vcpu *vcpu;
306+
int32_t ret;
306307

307-
if ((target_vm == NULL) || (param == 0U) || is_vm0(target_vm)) {
308-
return -1;
309-
}
310-
311-
/* Only allow setup init ctx while target_vm is inactive */
312-
if (target_vm->state == VM_STARTED) {
313-
return -1;
314-
}
315-
316-
if (copy_from_gpa(vm, &vcpu_regs, param, sizeof(vcpu_regs)) != 0) {
308+
if ((target_vm == NULL) || (param == 0U) || is_vm0(target_vm) || (target_vm->state == VM_STARTED)) {
309+
/* Only allow setup init ctx while target_vm is inactive */
310+
ret = -1;
311+
} else if (copy_from_gpa(vm, &vcpu_regs, param, sizeof(vcpu_regs)) != 0) {
317312
pr_err("%s: Unable copy param to vm\n", __func__);
318-
return -1;
319-
}
320-
321-
if (vcpu_regs.vcpu_id >= CONFIG_MAX_VCPUS_PER_VM) {
313+
ret = -1;
314+
} else if (vcpu_regs.vcpu_id >= CONFIG_MAX_VCPUS_PER_VM) {
322315
pr_err("%s: invalid vcpu_id for set_vcpu_regs\n", __func__);
323-
return -1;
316+
ret = -1;
317+
} else {
318+
vcpu = vcpu_from_vid(target_vm, vcpu_regs.vcpu_id);
319+
set_vcpu_regs(vcpu, &(vcpu_regs.vcpu_regs));
320+
ret = 0;
324321
}
325322

326-
vcpu = vcpu_from_vid(target_vm, vcpu_regs.vcpu_id);
327-
set_vcpu_regs(vcpu, &(vcpu_regs.vcpu_regs));
328-
329-
return 0;
323+
return ret;
330324
}
331325

332326
/**
@@ -348,29 +342,29 @@ int32_t hcall_set_irqline(const struct acrn_vm *vm, uint16_t vmid,
348342
{
349343
uint32_t irq_pic;
350344
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
345+
int32_t ret;
351346

352347
if (target_vm == NULL) {
353-
return -EINVAL;
354-
}
355-
356-
if (ops->gsi >= vioapic_pincount(vm)) {
357-
return -EINVAL;
358-
}
348+
ret = -EINVAL;
349+
} else if (ops->gsi >= vioapic_pincount(vm)) {
350+
ret = -EINVAL;
351+
} else {
352+
if (ops->gsi < vpic_pincount()) {
353+
/*
354+
* IRQ line for 8254 timer is connected to
355+
* I/O APIC pin #2 but PIC pin #0,route GSI
356+
* number #2 to PIC IRQ #0.
357+
*/
358+
irq_pic = (ops->gsi == 2U) ? 0U : ops->gsi;
359+
vpic_set_irq(target_vm, irq_pic, ops->op);
360+
}
359361

360-
if (ops->gsi < vpic_pincount()) {
361-
/*
362-
* IRQ line for 8254 timer is connected to
363-
* I/O APIC pin #2 but PIC pin #0,route GSI
364-
* number #2 to PIC IRQ #0.
365-
*/
366-
irq_pic = (ops->gsi == 2U) ? 0U : ops->gsi;
367-
vpic_set_irq(target_vm, irq_pic, ops->op);
362+
/* handle IOAPIC irqline */
363+
vioapic_set_irq(target_vm, ops->gsi, ops->op);
364+
ret = 0;
368365
}
369366

370-
/* handle IOAPIC irqline */
371-
vioapic_set_irq(target_vm, ops->gsi, ops->op);
372-
373-
return 0;
367+
return ret;
374368
}
375369

376370
/**

0 commit comments

Comments
 (0)