Skip to content

Commit 9f13a51

Browse files
Shawnshhlijinxia
authored andcommitted
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 <huihuang.shi@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent a7398e8 commit 9f13a51

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

hypervisor/common/hypercall.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ int32_t hcall_destroy_vm(uint16_t vmid)
157157
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
158158

159159
if (target_vm == NULL) {
160-
return -1;
160+
ret = -1;
161+
} else {
162+
ret = shutdown_vm(target_vm);
161163
}
162164

163-
ret = shutdown_vm(target_vm);
164165
return ret;
165166
}
166167

@@ -181,9 +182,8 @@ int32_t hcall_start_vm(uint16_t vmid)
181182
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
182183

183184
if (target_vm == NULL) {
184-
return -1;
185-
}
186-
if (target_vm->sw.io_shared_page == NULL) {
185+
ret = -1;
186+
} else if (target_vm->sw.io_shared_page == NULL) {
187187
ret = -1;
188188
} else {
189189
ret = start_vm(target_vm);
@@ -206,14 +206,16 @@ int32_t hcall_start_vm(uint16_t vmid)
206206
int32_t hcall_pause_vm(uint16_t vmid)
207207
{
208208
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
209+
int32_t ret;
209210

210211
if (target_vm == NULL) {
211-
return -1;
212+
ret = -1;
213+
} else {
214+
pause_vm(target_vm);
215+
ret = 0;
212216
}
213217

214-
pause_vm(target_vm);
215-
216-
return 0;
218+
return ret;
217219
}
218220

219221
/**
@@ -273,12 +275,14 @@ int32_t hcall_create_vcpu(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
273275
int32_t hcall_reset_vm(uint16_t vmid)
274276
{
275277
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
278+
int32_t ret;
276279

277280
if ((target_vm == NULL) || is_vm0(target_vm)) {
278-
return -1;
281+
ret = -1;
282+
} else {
283+
ret = reset_vm(target_vm);
279284
}
280-
281-
return reset_vm(target_vm);
285+
return ret;
282286
}
283287

284288
/**

0 commit comments

Comments
 (0)