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>
This commit is contained in:
Aaron Durbin 2016-08-05 15:41:37 -05:00 committed by Martin Roth
parent 4884c5d52d
commit 367f2b9568

View file

@ -622,7 +622,7 @@ int elog_clear(void)
return elog_prepare_empty(); return elog_prepare_empty();
} }
static void elog_find_flash(void) static int elog_find_flash(void)
{ {
struct region r; struct region r;
size_t reserved_space = ELOG_MIN_AVAILABLE_ENTRIES * MAX_EVENT_SIZE; 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 */ /* Find the ELOG base and size in FMAP */
if (fmap_locate_area("RW_ELOG", &r) < 0) { if (fmap_locate_area("RW_ELOG", &r) < 0) {
printk(BIOS_WARNING, "ELOG: Unable to find RW_ELOG in FMAP\n"); printk(BIOS_WARNING, "ELOG: Unable to find RW_ELOG in FMAP\n");
flash_base = total_size = 0; return -1;
} 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));
} }
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; full_threshold = total_size - reserved_space;
shrink_size = MIN(total_size * ELOG_SHRINK_PERCENTAGE / 100, shrink_size = total_size * ELOG_SHRINK_PERCENTAGE / 100;
full_threshold);
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) static int elog_sync_to_nv(void)
@ -711,18 +723,8 @@ int elog_init(void)
} }
/* Set up the backing store */ /* Set up the backing store */
elog_find_flash(); if (elog_find_flash() < 0)
if (flash_base == 0) {
printk(BIOS_ERR, "ELOG: Invalid flash base\n");
return -1; 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); mirror_buffer = malloc(total_size);
if (!mirror_buffer) { if (!mirror_buffer) {