From 279808b202ab0cdb12f37319419f9e4704d9909a Mon Sep 17 00:00:00 2001 From: Huihuang Shi Date: Thu, 29 Nov 2018 11:09:12 +0800 Subject: [PATCH] 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 Acked-by: Eddie Dong --- hypervisor/arch/x86/mmu.c | 6 ++---- hypervisor/arch/x86/mtrr.c | 37 ++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index ef8824a72..0345654d9 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -156,11 +156,9 @@ uint16_t allocate_vpid(void) void flush_vpid_single(uint16_t vpid) { - if (vpid == 0U) { - return; + if (vpid != 0U) { + local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL); } - - local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL); } void flush_vpid_global(void) diff --git a/hypervisor/arch/x86/mtrr.c b/hypervisor/arch/x86/mtrr.c index e4ef81a63..74255733b 100644 --- a/hypervisor/arch/x86/mtrr.c +++ b/hypervisor/arch/x86/mtrr.c @@ -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)) { 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 (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); - - for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) { - /* If it's same type, combine the subrange together */ - if (type == vcpu->mtrr.fixed_range[i].type[j]) { - 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); + for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) { + /* If it's same type, combine the subrange together */ + if (type == vcpu->mtrr.fixed_range[i].type[j]) { + 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); + } } }