cpu/x86/mtrr: Assert that MSR arrays are fully initialized

The initialization logic for the fixed_msrs and msr_index arrays depends
on the contents of the fixed MTRR descriptor. However, Coverity is unable
to check these values and believes (incorrectly) that the arrays may not
be entirely initialized. An assert was added in commit b28025a434 to
ensure that one of the loops is entered, but it is simplest to just
check that msr_num has iterated over the entire array after the loops
are over. This also acts as a sanity check that the values in the MTRR
descriptor were hardcoded correctly.

Change-Id: Ia573792f74aa6ea5e659c1e2253f112184fbb0a5
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Found-by: Coverity CID 1370582
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33048
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Lance Zhao <lance.zhao@gmail.com>
This commit is contained in:
Jacob Garber 2019-05-28 11:47:49 -06:00 committed by Patrick Georgi
parent bdcb4d3750
commit 5b922726e1
1 changed files with 3 additions and 1 deletions

View File

@ -331,7 +331,6 @@ static void commit_fixed_mtrrs(void)
desc = &fixed_mtrr_desc[i]; desc = &fixed_mtrr_desc[i];
num_ranges = (desc->end - desc->begin) / desc->step; num_ranges = (desc->end - desc->begin) / desc->step;
ASSERT(num_ranges > 0);
for (j = 0; j < num_ranges; j += RANGES_PER_FIXED_MTRR) { for (j = 0; j < num_ranges; j += RANGES_PER_FIXED_MTRR) {
msr_index[msr_num] = desc->msr_index_base + msr_index[msr_num] = desc->msr_index_base +
(j / RANGES_PER_FIXED_MTRR); (j / RANGES_PER_FIXED_MTRR);
@ -355,6 +354,9 @@ static void commit_fixed_mtrrs(void)
} }
} }
/* Ensure that both arrays were fully initialized */
ASSERT(msr_num == NUM_FIXED_MTRRS)
for (i = 0; i < ARRAY_SIZE(fixed_msrs); i++) for (i = 0; i < ARRAY_SIZE(fixed_msrs); i++)
printk(BIOS_DEBUG, "MTRR: Fixed MSR 0x%lx 0x%08x%08x\n", printk(BIOS_DEBUG, "MTRR: Fixed MSR 0x%lx 0x%08x%08x\n",
msr_index[i], fixed_msrs[i].hi, fixed_msrs[i].lo); msr_index[i], fixed_msrs[i].hi, fixed_msrs[i].lo);