From 9f13a51e8a587dd083c3659c874f9e9a53a524db Mon Sep 17 00:00:00 2001 From: Huihuang Shi Date: Mon, 26 Nov 2018 13:48:38 +0800 Subject: [PATCH] hv: hypercall: VM management fix "Procedure has more than one exit point" IEC 61508,ISO 26262 standards highly recommend single-exit rule. Reduce the count of the "return entries". Fix the violations which is comply with the cases list below: 1.Function has 2 return entries. 2.The first return entry is used to return the error code of checking variable whether is valid. Fix the violations in "if else" format. V1->V2: update the git comment to describe why comply with the single-exit rule. V2->V3: update the git comment title to give a scope declaration of this patch. Tracked-On: #861 Signed-off-by: Huihuang Shi Reviewed-by: Li, Fei1 Acked-by: Eddie Dong --- hypervisor/common/hypercall.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 71e39cd2b..2d8be9244 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -157,10 +157,11 @@ int32_t hcall_destroy_vm(uint16_t vmid) struct acrn_vm *target_vm = get_vm_from_vmid(vmid); if (target_vm == NULL) { - return -1; + ret = -1; + } else { + ret = shutdown_vm(target_vm); } - ret = shutdown_vm(target_vm); return ret; } @@ -181,9 +182,8 @@ int32_t hcall_start_vm(uint16_t vmid) struct acrn_vm *target_vm = get_vm_from_vmid(vmid); if (target_vm == NULL) { - return -1; - } - if (target_vm->sw.io_shared_page == NULL) { + ret = -1; + } else if (target_vm->sw.io_shared_page == NULL) { ret = -1; } else { ret = start_vm(target_vm); @@ -206,14 +206,16 @@ int32_t hcall_start_vm(uint16_t vmid) int32_t hcall_pause_vm(uint16_t vmid) { struct acrn_vm *target_vm = get_vm_from_vmid(vmid); + int32_t ret; if (target_vm == NULL) { - return -1; + ret = -1; + } else { + pause_vm(target_vm); + ret = 0; } - pause_vm(target_vm); - - return 0; + return ret; } /** @@ -273,12 +275,14 @@ int32_t hcall_create_vcpu(struct acrn_vm *vm, uint16_t vmid, uint64_t param) int32_t hcall_reset_vm(uint16_t vmid) { struct acrn_vm *target_vm = get_vm_from_vmid(vmid); + int32_t ret; if ((target_vm == NULL) || is_vm0(target_vm)) { - return -1; + ret = -1; + } else { + ret = reset_vm(target_vm); } - - return reset_vm(target_vm); + return ret; } /**