efi_loader: Clean up file size calculations

Message ID 20210325195516.1265125-1-ilias.apalodimas@linaro.org
State Accepted
Commit ac30aad21076e9eeb460af2865b863f3ae3d2eaa
Headers show
Series
  • efi_loader: Clean up file size calculations
Related show

Commit Message

Ilias Apalodimas March 25, 2021, 7:55 p.m.
We recently added a common function for calculating file size,
instead of copy pasting the code around.  Switch one of the 
occurences over to the common function

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

---
 lib/efi_loader/efi_boottime.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

-- 
2.31.0

Comments

Heinrich Schuchardt March 25, 2021, 8:03 p.m. | #1
On 3/25/21 8:55 PM, Ilias Apalodimas wrote:
> We recently added a common function for calculating file size,

> instead of copy pasting the code around.  Switch one of the

> occurences over to the common function

>

> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Patch

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 41b8949b0424..a21abefd8ca8 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1877,7 +1877,6 @@  static
 efi_status_t efi_load_image_from_file(struct efi_device_path *file_path,
 				      void **buffer, efi_uintn_t *size)
 {
-	struct efi_file_info *info = NULL;
 	struct efi_file_handle *f;
 	efi_status_t ret;
 	u64 addr;
@@ -1888,18 +1887,7 @@  efi_status_t efi_load_image_from_file(struct efi_device_path *file_path,
 	if (!f)
 		return EFI_NOT_FOUND;
 
-	/* Get file size */
-	bs = 0;
-	EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid,
-				  &bs, info));
-	if (ret != EFI_BUFFER_TOO_SMALL) {
-		ret =  EFI_DEVICE_ERROR;
-		goto error;
-	}
-
-	info = malloc(bs);
-	EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, &bs,
-				  info));
+	ret = efi_file_size(f, &bs);
 	if (ret != EFI_SUCCESS)
 		goto error;
 
@@ -1909,7 +1897,6 @@  efi_status_t efi_load_image_from_file(struct efi_device_path *file_path,
 	 * allocate a buffer as EFI_BOOT_SERVICES_DATA. The caller has to
 	 * update the reservation according to the image type.
 	 */
-	bs = info->file_size;
 	ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
 				 EFI_BOOT_SERVICES_DATA,
 				 efi_size_in_pages(bs), &addr);
@@ -1926,7 +1913,6 @@  efi_status_t efi_load_image_from_file(struct efi_device_path *file_path,
 	*size = bs;
 error:
 	EFI_CALL(f->close(f));
-	free(info);
 	return ret;
 }