diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-18 20:59:05 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-25 17:10:51 +0200 |
commit | 1aaabb17fd634a977475e5592c9aa9ad46cadc03 (patch) | |
tree | 4b187e1d9b2e761e79afa98a081d4d21b7a6ea9c /src/boot | |
parent | 5373172e80e90c7a108693a83f2586d18e9c99b5 (diff) | |
download | systemd-1aaabb17fd634a977475e5592c9aa9ad46cadc03.tar.gz |
efi: modernize file_read() a bit
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/util.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 4134e2200a..6d2ad3d50b 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -309,8 +309,8 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c) { return NULL; } -EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size) { - EFI_FILE_HANDLE handle; +EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) { + _cleanup_(FileHandleClosep) EFI_FILE_HANDLE handle = NULL; _cleanup_freepool_ CHAR8 *buf = NULL; EFI_STATUS err; @@ -322,6 +322,9 @@ EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN s _cleanup_freepool_ EFI_FILE_INFO *info; info = LibFileInfo(handle); + if (!info) + return EFI_OUT_OF_RESOURCES; + size = info->FileSize+1; } @@ -332,15 +335,18 @@ EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN s } buf = AllocatePool(size + 1); + if (!buf) + return EFI_OUT_OF_RESOURCES; + err = uefi_call_wrapper(handle->Read, 3, handle, &size, buf); - if (!EFI_ERROR(err)) { - buf[size] = '\0'; - *content = buf; - buf = NULL; - if (content_size) - *content_size = size; - } - uefi_call_wrapper(handle->Close, 1, handle); + if (EFI_ERROR(err)) + return err; + + buf[size] = '\0'; + + *ret = TAKE_PTR(buf); + if (ret_size) + *ret_size = size; return err; } |