Jacob Garber has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/34916 )
Change subject: em100: Fix malloc() failure checks ......................................................................
em100: Fix malloc() failure checks
The checks should be readback == NULL, since those are the buffers that we just allocated. The check for data == NULL was already done earlier. We also need to free() the data buffer if these allocations fail.
Change-Id: Ibc798673a3ce6796bf036bd962da248d12dee47c Signed-off-by: Jacob Garber jgarber1@ualberta.ca --- M em100.c 1 file changed, 4 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/16/34916/1
diff --git a/em100.c b/em100.c index 64a4ab2..f861ffe 100644 --- a/em100.c +++ b/em100.c @@ -827,8 +827,9 @@
if (spi_start_address) { readback = malloc(maxlen); - if (data == NULL) { + if (readback == NULL) { printf("FATAL: couldn't allocate memory(size: %x)\n", maxlen); + free(data); return 1; } done = read_sdram(&em100, readback, 0, maxlen); @@ -841,8 +842,9 @@
if (verify) { readback = malloc(length); - if (data == NULL) { + if (readback == NULL) { printf("FATAL: couldn't allocate memory\n"); + free(data); return 1; } done = read_sdram(&em100, readback, spi_start_address, length);
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/em100/+/34916 )
Change subject: em100: Fix malloc() failure checks ......................................................................
Patch Set 1: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/em100/+/34916 )
Change subject: em100: Fix malloc() failure checks ......................................................................
em100: Fix malloc() failure checks
The checks should be readback == NULL, since those are the buffers that we just allocated. The check for data == NULL was already done earlier. We also need to free() the data buffer if these allocations fail.
Change-Id: Ibc798673a3ce6796bf036bd962da248d12dee47c Signed-off-by: Jacob Garber jgarber1@ualberta.ca Reviewed-on: https://review.coreboot.org/c/em100/+/34916 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Patrick Georgi pgeorgi@google.com --- M em100.c 1 file changed, 4 insertions(+), 2 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Georgi: Looks good to me, approved
diff --git a/em100.c b/em100.c index b6b23df..db550c7 100644 --- a/em100.c +++ b/em100.c @@ -827,8 +827,9 @@
if (spi_start_address) { readback = malloc(maxlen); - if (data == NULL) { + if (readback == NULL) { printf("FATAL: couldn't allocate memory(size: %x)\n", maxlen); + free(data); return 1; } done = read_sdram(&em100, readback, 0, maxlen); @@ -845,8 +846,9 @@
if (verify) { readback = malloc(length); - if (data == NULL) { + if (readback == NULL) { printf("FATAL: couldn't allocate memory\n"); + free(data); return 1; } done = read_sdram(&em100, readback, spi_start_address, length);