Merge tag 'efi-2021-07-rc1-2' of https://source.denx.de/u-boot/custodians/u-boot-efi

Pull request for efi-2021-07-rc1-2

Documentation:
	man-page for fatinfo

Bug fixes:
	memory leak in efi_capsule_scan_dir()
	incorrect invocations of EFI_CALL macro creating ESRT table
	buffer overflow in tcg2_create_digest()
diff --git a/doc/board/toradex/apalix-imx8x.rst b/doc/board/toradex/apalix-imx8x.rst
index efa7e0c..e62578b 100644
--- a/doc/board/toradex/apalix-imx8x.rst
+++ b/doc/board/toradex/apalix-imx8x.rst
@@ -1,7 +1,7 @@
 .. SPDX-License-Identifier: GPL-2.0+
 
 Apalis iMX8X V1.1A Module (SoC NXP i.MX8QXP RevB)
-==========================
+=================================================
 
 Quick Start
 -----------
diff --git a/doc/chromium/overview.rst b/doc/chromium/overview.rst
index 5498ed9..790233c 100644
--- a/doc/chromium/overview.rst
+++ b/doc/chromium/overview.rst
@@ -45,7 +45,7 @@
      - Presented at Open Source Firmware Conference 2018, Erlangen
      - Describes the work in progress as at the end of 2018
      - Slides at `OSFC <https://2018.osfc.io/uploads/talk/paper/26/U-Boot_with_Chrome_OS_and_firmware_packaging.pdf>`_
-     - Video on `Youtube <https://www.youtube.com/watch?v=1jknxUvmwpo>`_
+     - `Youtube video 'OSFC - U-Boot with Chrome OS and firmware packaging' <https://www.youtube.com/watch?v=1jknxUvmwpo>`_
 
    - "Verified Boot in Chrome OS and how to make it work for you"
 
@@ -58,7 +58,7 @@
        and pit/pi (`Samsung Chromebook 2 <https://www.cnet.com/products/samsung-chromebook-2-xe503c12-11-6-exynos-5-octa-4-gb-ram-16-gb-ssd/>`_
        with Exynos 5 Octa 5420 in 2014).
      - Slides at `Google research <https://research.google/pubs/pub42038/>`_
-     - Video at `Youtube <https://www.youtube.com/watch?v=kdpZC9jFzZA>`_
+     - `Youtube video 'Verified Boot on Chrome OS and How to do it yourself' <https://www.youtube.com/watch?v=kdpZC9jFzZA>`_
 
    - "Chrome University 2018: Chrome OS Firmware and Verified Boot 201"
 
@@ -67,7 +67,7 @@
        topics. This has no U-Boot information, but does cover coreboot and also
        talks about the Chrome OS EC and Security chip. This is probably the
        best introduction talk.
-     - Video at `YouTube <https://www.youtube.com/watch?v=WY2sWpuda2g>`_
+     - `Youtube video 'Chrome University 2018: Chrome OS Firmware and Verified Boot 201' <https://www.youtube.com/watch?v=WY2sWpuda2g>`_
 
    - `Chromium OS U-Boot <https://www.chromium.org/developers/u-boot>`_
 
diff --git a/doc/imx/misc/psb.rst b/doc/imx/misc/psb.rst
index 4d6f001..9bb84b4 100644
--- a/doc/imx/misc/psb.rst
+++ b/doc/imx/misc/psb.rst
@@ -88,7 +88,7 @@
 SIT is a 20 byte long structure containing of 5 32-bit words. Those encode
 bootloader B-copy area offset (called "firstSectorNumber"), magic value
 (called "tag") that is always 0x00112233, and three unused words set to 0.
-SIT is documented in [1] and [2]. Example SIT are below::
+SIT is documented in [1]_ and [2]_. Example SIT are below::
 
   $ hexdump -vC sit-mx7d.bin
     00000000  00 00 00 00
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index d330b14..b64cfe4 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -28,6 +28,7 @@
    exception
    exit
    false
+   fatinfo
    for
    load
    loady
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 9df9c35..691eda5 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -756,8 +756,11 @@
 		tmp_size = dirent_size;
 		ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent));
 		if (ret == EFI_BUFFER_TOO_SMALL) {
+			struct efi_file_info *old_dirent = dirent;
+
 			dirent = realloc(dirent, tmp_size);
 			if (!dirent) {
+				dirent = old_dirent;
 				ret = EFI_OUT_OF_RESOURCES;
 				goto err;
 			}
diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c
index 40f5326..3ca55ce 100644
--- a/lib/efi_loader/efi_esrt.c
+++ b/lib/efi_loader/efi_esrt.c
@@ -139,7 +139,7 @@
 
 	/* If there was a previous ESRT, deallocate its memory now. */
 	if (esrt)
-		ret = EFI_CALL(efi_free_pool(esrt));
+		ret = efi_free_pool(esrt);
 
 	esrt = new_esrt;
 
@@ -253,8 +253,8 @@
 		return EFI_INVALID_PARAMETER;
 	}
 
-	ret = EFI_CALL(efi_allocate_pool(EFI_BOOT_SERVICES_DATA, info_size,
-					 (void **)&img_info));
+	ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, info_size,
+				(void **)&img_info);
 	if (ret != EFI_SUCCESS) {
 		EFI_PRINT("ESRT failed to allocate memory for image info.\n");
 		return ret;
@@ -298,7 +298,7 @@
 	}
 
 out:
-	EFI_CALL(efi_free_pool(img_info));
+	efi_free_pool(img_info);
 	return EFI_SUCCESS;
 }
 
@@ -384,8 +384,8 @@
 			goto out;
 		}
 
-		ret = EFI_CALL(efi_allocate_pool(EFI_BOOT_SERVICES_DATA, info_size,
-						 (void **)&img_info));
+		ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, info_size,
+					(void **)&img_info);
 		if (ret != EFI_SUCCESS) {
 			EFI_PRINT("ESRT failed to allocate memory for image info\n");
 			goto out;
@@ -405,13 +405,13 @@
 
 		if (ret != EFI_SUCCESS) {
 			EFI_PRINT("ESRT failed to obtain image info from FMP\n");
-			EFI_CALL(efi_free_pool(img_info));
+			efi_free_pool(img_info);
 			goto out;
 		}
 
 		num_entries += desc_count;
 
-		EFI_CALL(efi_free_pool(img_info));
+		efi_free_pool(img_info);
 	}
 
 	EFI_PRINT("ESRT create table with %u entries\n", num_entries);
@@ -430,9 +430,9 @@
 	 */
 	it_handle = base_handle;
 	for (u32 idx = 0; idx < no_handles; idx++, it_handle++) {
-		ret = EFI_CALL(efi_search_protocol(*it_handle,
-						   &efi_guid_firmware_management_protocol,
-						   &handler));
+		ret = efi_search_protocol(*it_handle,
+					  &efi_guid_firmware_management_protocol,
+					  &handler);
 
 		if (ret != EFI_SUCCESS) {
 			EFI_PRINT("ESRT unable to find FMP handle (%u)\n",
@@ -448,7 +448,7 @@
 
 out:
 
-	EFI_CALL(efi_free_pool(base_handle));
+	efi_free_pool(base_handle);
 
 	return ret;
 }
@@ -490,8 +490,8 @@
 		return ret;
 	}
 
-	ret = EFI_CALL(efi_create_event(EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
-					efi_esrt_new_fmp_notify, NULL, NULL, &ev));
+	ret = efi_create_event(EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
+			       efi_esrt_new_fmp_notify, NULL, NULL, &ev);
 	if (ret != EFI_SUCCESS) {
 		EFI_PRINT("ESRT failed to create event\n");
 		return ret;
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index ed86a22..d5eca68 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -515,7 +515,7 @@
 	sha1_context ctx;
 	sha256_context ctx_256;
 	sha512_context ctx_512;
-	u8 final[TPM2_ALG_SHA512];
+	u8 final[TPM2_SHA512_DIGEST_SIZE];
 	efi_status_t ret;
 	u32 active;
 	int i;