cpu/x86/mtrr/mtrr.c:Avoid static scan false positive

Static scan does not know the contents of the fixed MTRR descriptor, so
it has no way to eval the result for variable num_ranges. If num_ranges
is less or equal to 0, the for loop will not be entered, and the values
of fixed_msrs will not be set. Asserting that num_ranges is greater than
0 ensures the loop enters at least once.

BUG=b:112253891
TEST=build grunt

Change-Id: Ieec0ac432c745bde4b1700539c266625da6cfd77
Signed-off-by: Richard Spiegel <richard.spiegel@silverbackltd.com>
Reviewed-on: https://review.coreboot.org/c/31527
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Richard Spiegel 2019-02-20 11:00:19 -07:00 committed by Patrick Georgi
parent c60c3269ec
commit b28025a434
1 changed files with 2 additions and 0 deletions

View File

@ -36,6 +36,7 @@
#include <arch/acpi.h> #include <arch/acpi.h>
#include <memrange.h> #include <memrange.h>
#include <cpu/amd/mtrr.h> #include <cpu/amd/mtrr.h>
#include <assert.h>
#if IS_ENABLED(CONFIG_X86_AMD_FIXED_MTRRS) #if IS_ENABLED(CONFIG_X86_AMD_FIXED_MTRRS)
#define MTRR_FIXED_WRBACK_BITS (MTRR_READ_MEM | MTRR_WRITE_MEM) #define MTRR_FIXED_WRBACK_BITS (MTRR_READ_MEM | MTRR_WRITE_MEM)
#else #else
@ -331,6 +332,7 @@ 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);