Skip to content

Commit 279808b

Browse files
Shawnshhwenlingz
authored andcommitted
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>
1 parent ddb5483 commit 279808b

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

hypervisor/arch/x86/mmu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,9 @@ uint16_t allocate_vpid(void)
156156

157157
void flush_vpid_single(uint16_t vpid)
158158
{
159-
if (vpid == 0U) {
160-
return;
159+
if (vpid != 0U) {
160+
local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL);
161161
}
162-
163-
local_invvpid(VMX_VPID_TYPE_SINGLE_CONTEXT, vpid, 0UL);
164162
}
165163

166164
void flush_vpid_global(void)

hypervisor/arch/x86/mtrr.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,27 @@ static void update_ept_mem_type(const struct acrn_vcpu *vcpu)
165165
*/
166166
if (!is_mtrr_enabled(vcpu) || !is_fixed_range_mtrr_enabled(vcpu)) {
167167
update_ept(vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vcpu));
168-
return;
169-
}
170-
171-
/* Deal with fixed-range MTRRs only */
172-
for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) {
173-
type = vcpu->mtrr.fixed_range[i].type[0];
174-
start = get_subrange_start_of_fixed_mtrr(i, 0U);
175-
size = get_subrange_size_of_fixed_mtrr(i);
176-
177-
for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) {
178-
/* If it's same type, combine the subrange together */
179-
if (type == vcpu->mtrr.fixed_range[i].type[j]) {
180-
size += get_subrange_size_of_fixed_mtrr(i);
181-
} else {
182-
update_ept(vcpu->vm, start, size, type);
183-
type = vcpu->mtrr.fixed_range[i].type[j];
184-
start = get_subrange_start_of_fixed_mtrr(i, j);
185-
size = get_subrange_size_of_fixed_mtrr(i);
168+
} else {
169+
/* Deal with fixed-range MTRRs only */
170+
for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) {
171+
type = vcpu->mtrr.fixed_range[i].type[0];
172+
start = get_subrange_start_of_fixed_mtrr(i, 0U);
173+
size = get_subrange_size_of_fixed_mtrr(i);
174+
175+
for (j = 1U; j < MTRR_SUB_RANGE_NUM; j++) {
176+
/* If it's same type, combine the subrange together */
177+
if (type == vcpu->mtrr.fixed_range[i].type[j]) {
178+
size += get_subrange_size_of_fixed_mtrr(i);
179+
} else {
180+
update_ept(vcpu->vm, start, size, type);
181+
type = vcpu->mtrr.fixed_range[i].type[j];
182+
start = get_subrange_start_of_fixed_mtrr(i, j);
183+
size = get_subrange_size_of_fixed_mtrr(i);
184+
}
186185
}
187-
}
188186

189-
update_ept(vcpu->vm, start, size, type);
187+
update_ept(vcpu->vm, start, size, type);
188+
}
190189
}
191190
}
192191

0 commit comments

Comments
 (0)