Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33134
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
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 jgarber1@ualberta.ca Found-by: Coverity CID 1399147 --- M src/mainboard/sifive/hifive-unleashed/fixup_fdt.c 1 file changed, 11 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/34/33134/1
diff --git a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c index ea58e02..6c42fc8 100644 --- a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c +++ b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c @@ -86,6 +86,11 @@ /* 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 +100,12 @@
/* 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 */
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/33134
to look at the new patch set (#2).
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
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 jgarber1@ualberta.ca Found-by: Coverity CID 1399147 --- M src/mainboard/sifive/hifive-unleashed/fixup_fdt.c 1 file changed, 12 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/34/33134/2
Jacob Garber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33134 )
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
Patch Set 2:
I'm not sure of the severity of these failures, but I used BIOS_ERR for now.
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33134 )
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
Patch Set 2: Code-Review+2
Xiang Wang has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33134 )
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
Patch Set 2: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/33134 )
Change subject: mb/sifive/hifive-unleashed: Check for errors in fixup_fdt ......................................................................
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 jgarber1@ualberta.ca Found-by: Coverity CID 1399147 Reviewed-on: https://review.coreboot.org/c/coreboot/+/33134 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Patrick Rudolph siro@das-labor.org Reviewed-by: Xiang Wang wxjstz@126.com --- M src/mainboard/sifive/hifive-unleashed/fixup_fdt.c 1 file changed, 12 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Rudolph: Looks good to me, approved Xiang Wang: Looks good to me, approved
diff --git a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c index ea58e02..8ac6ff1 100644 --- a/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c +++ b/src/mainboard/sifive/hifive-unleashed/fixup_fdt.c @@ -15,6 +15,7 @@
#include <stdint.h> #include <string.h> +#include <console/console.h> #include <soc/otp.h> #include <soc/sdram.h> #include <cbfs.h> @@ -86,6 +87,11 @@ /* 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 @@
/* 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 */