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;
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;
* 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);
*size = bs;
error:
EFI_CALL(f->close(f));
- free(info);
return ret;
}