diff options
author | Aaron Durbin <adurbin@chromium.org> | 2016-08-05 15:41:37 -0500 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-08-09 19:51:40 +0200 |
commit | 367f2b9568e03ad8ccb637a8f53623bf5eab4b7c (patch) | |
tree | bfa9e12523264ce0f81807e8c1f974419066bd98 /src | |
parent | 4884c5d52d23ca02be326d41233dc16b829d6535 (diff) | |
download | coreboot-367f2b9568e03ad8ccb637a8f53623bf5eab4b7c.tar.xz |
drivers/elog: consolidate checks in elog_find_flash()
There were checks against global variables trying to determine
failing cases of elog_find_flash(). Instead move the checks
into elog_find_flash() and return value indicating failure.
A minimum 4KiB check was added to ensure the eventlog is at
least that size which makes the heuristic checks cleaner.
BUG=chrome-os-partner:55932
Change-Id: I4d9d13148555e05d4f217a10f995831a0e437fc3
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/16101
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/elog/elog.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index 036ab91493..ea7597fee8 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -622,7 +622,7 @@ int elog_clear(void) return elog_prepare_empty(); } -static void elog_find_flash(void) +static int elog_find_flash(void) { struct region r; size_t reserved_space = ELOG_MIN_AVAILABLE_ENTRIES * MAX_EVENT_SIZE; @@ -632,16 +632,28 @@ static void elog_find_flash(void) /* Find the ELOG base and size in FMAP */ if (fmap_locate_area("RW_ELOG", &r) < 0) { printk(BIOS_WARNING, "ELOG: Unable to find RW_ELOG in FMAP\n"); - flash_base = total_size = 0; - } else { - flash_base = region_offset(&r); - /* Keep 4KiB max size until large malloc()s have been fixed. */ - total_size = MIN(4*KiB, region_sz(&r)); + return -1; + } + + if (region_sz(&r) < 4*KiB) { + printk(BIOS_WARNING, "ELOG: Needs a minium size of 4KiB: %zu\n", + region_sz(&r)); + return -1; } + flash_base = region_offset(&r); + /* Keep 4KiB max size until large malloc()s have been fixed. */ + total_size = MIN(4*KiB, region_sz(&r)); + full_threshold = total_size - reserved_space; - shrink_size = MIN(total_size * ELOG_SHRINK_PERCENTAGE / 100, - full_threshold); + shrink_size = total_size * ELOG_SHRINK_PERCENTAGE / 100; + + if (reserved_space > shrink_size) { + printk(BIOS_ERR, "ELOG: SHRINK_PERCENTAGE too small\n"); + return -1; + } + + return 0; } static int elog_sync_to_nv(void) @@ -711,18 +723,8 @@ int elog_init(void) } /* Set up the backing store */ - elog_find_flash(); - if (flash_base == 0) { - printk(BIOS_ERR, "ELOG: Invalid flash base\n"); + if (elog_find_flash() < 0) return -1; - } else if (total_size < sizeof(struct elog_header) + MAX_EVENT_SIZE) { - printk(BIOS_ERR, "ELOG: Region too small to hold any events\n"); - return -1; - } else if (total_size - shrink_size >= full_threshold) { - printk(BIOS_ERR, - "ELOG: SHRINK_PERCENTAGE set too small for MIN_AVAILABLE_ENTRIES\n"); - return -1; - } mirror_buffer = malloc(total_size); if (!mirror_buffer) { |