[coreboot-gerrit] Patch set updated for coreboot: drivers/elog: consolidate checks in elog_find_flash()

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Mon Aug 8 02:02:42 CEST 2016


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16101

-gerrit

commit 1b04f57f14da8b4775acd4e0c7e0bdde926e22ec
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Fri Aug 5 15:41:37 2016 -0500

    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 at chromium.org>
---
 src/drivers/elog/elog.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c
index 036ab91..ea7597f 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) {



More information about the coreboot-gerrit mailing list