From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Sun, 1 May 2022 09:34:15 +0000 (+0200)
Subject: efi_selftest: error handling in efi_selftest_tcg2
X-Git-Tag: v2025.01-rc5-pxa1908~1419^2~10
X-Git-Url: http://git.dujemihanovic.xyz/img/static/gitweb.css?a=commitdiff_plain;h=c900a42eb0a82d3d7cd18f3255acf92dd9894b92;p=u-boot.git

efi_selftest: error handling in efi_selftest_tcg2

If memory allocation fails, write an error message.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---

diff --git a/lib/efi_selftest/efi_selftest_tcg2.c b/lib/efi_selftest/efi_selftest_tcg2.c
index a2b4a79e9b..67a886efaa 100644
--- a/lib/efi_selftest/efi_selftest_tcg2.c
+++ b/lib/efi_selftest/efi_selftest_tcg2.c
@@ -631,8 +631,10 @@ static int efi_st_tcg2_setup(const efi_handle_t img_handle,
 				      sizeof(struct efi_tcg2_event) +
 				      sizeof(struct uefi_image_load_event),
 				      (void **)&efi_tcg2_event);
-	if (!efi_tcg2_event)
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("Out of memory\n");
 		return EFI_ST_FAILURE;
+	}
 
 	efi_tcg2_event->size = sizeof(struct efi_tcg2_event) +
 			       sizeof(struct uefi_image_load_event);
@@ -659,8 +661,10 @@ static int efi_st_tcg2_setup(const efi_handle_t img_handle,
 				      (EFI_TCG2_MAX_PCR_INDEX + 1) *
 				      TPM2_SHA256_DIGEST_SIZE,
 				      (void **)&pcrs);
-	if (!pcrs)
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("Out of memory\n");
 		return EFI_ST_FAILURE;
+	}
 
 	boottime->set_mem(pcrs, (EFI_TCG2_MAX_PCR_INDEX + 1) * TPM2_SHA256_DIGEST_SIZE, 0);