From 7da638c20e4c56bc103be23216862e265b3ca8b1 Mon Sep 17 00:00:00 2001 From: Jacob Garber Date: Thu, 30 May 2019 16:11:41 -0600 Subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt It is possible that cbfs_boot_map_with_leak() and malloc() could fail, so detect those conditions and print error messages if they do. Change-Id: I34951da0b73028c4c89446cb1779a72422997325 Signed-off-by: Jacob Garber Found-by: Coverity CID 1399147 Reviewed-on: https://review.coreboot.org/c/coreboot/+/33134 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Rudolph Reviewed-by: Xiang Wang --- src/mainboard/sifive/hifive-unleashed/fixup_fdt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/mainboard') diff --git a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c index ea58e02b2e..8ac6ff1208 100644 --- a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c +++ b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -86,6 +87,11 @@ static void fixup_fdt(void *unused) /* load flat dt from cbfs */ fdt_rom = cbfs_boot_map_with_leak("fallback/DTB", CBFS_TYPE_RAW, NULL); + if (fdt_rom == NULL) { + printk(BIOS_ERR, "Unable to load fallback/DTB from CBFS\n"); + return; + } + /* Expand DT into a tree */ tree = fdt_unflatten(fdt_rom); @@ -95,6 +101,12 @@ static void fixup_fdt(void *unused) /* convert the tree to a flat dt */ void *dt = malloc(dt_flat_size(tree)); + + if (dt == NULL) { + printk(BIOS_ERR, "Unable to allocate memory for flat device tree\n"); + return; + } + dt_flatten(tree, dt); /* update HLS */ -- cgit v1.2.3