hv: memory: 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.

Tracked-On: #861
Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Huihuang Shi 2018-11-29 11:09:12 +08:00 committed by wenlingz
parent ddb548367a
commit 279808b202
2 changed files with 20 additions and 23 deletions

View File

@ -156,11 +156,9 @@ uint16_t allocate_vpid(void)
void flush_vpid_single(uint16_t vpid) void flush_vpid_single(uint16_t vpid)
{ {
if (vpid == 0U) { if (vpid != 0U) {
return; local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL);
} }
local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL);
} }
void flush_vpid_global(void) void flush_vpid_global(void)

View File

@ -165,28 +165,27 @@ static void update_ept_mem_type(const struct acrn_vcpu *vcpu)
*/ */
if (!is_mtrr_enabled(vcpu) || !is_fixed_range_mtrr_enabled(vcpu)) { if (!is_mtrr_enabled(vcpu) || !is_fixed_range_mtrr_enabled(vcpu)) {
update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vcpu)); update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vcpu));
return; } else {
} /* Deal with fixed-range MTRRs only */
for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) {
type = vcpu->mtrr.fixed_range[i].type[0];
start = get_subrange_start_of_fixed_mtrr(i, 0U);
size = get_subrange_size_of_fixed_mtrr(i);
/* Deal with fixed-range MTRRs only */ for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) {
for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) { /* If it's same type, combine the subrange together */
type = vcpu->mtrr.fixed_range[i].type[0]; if (type == vcpu->mtrr.fixed_range[i].type[j]) {
start = get_subrange_start_of_fixed_mtrr(i, 0U); size += get_subrange_size_of_fixed_mtrr(i);
size = get_subrange_size_of_fixed_mtrr(i); } else {
update_ept(vcpu->vm, start, size, type);
for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) { type = vcpu->mtrr.fixed_range[i].type[j];
/* If it's same type, combine the subrange together */ start = get_subrange_start_of_fixed_mtrr(i, j);
if (type == vcpu->mtrr.fixed_range[i].type[j]) { size = get_subrange_size_of_fixed_mtrr(i);
size += get_subrange_size_of_fixed_mtrr(i); }
} else {
update_ept(vcpu->vm, start, size, type);
type = vcpu->mtrr.fixed_range[i].type[j];
start = get_subrange_start_of_fixed_mtrr(i, j);
size = get_subrange_size_of_fixed_mtrr(i);
} }
}
update_ept(vcpu->vm, start, size, type); update_ept(vcpu->vm, start, size, type);
}
} }
} }