summaryrefslogtreecommitdiff
path: root/kjarna/efi/file.c
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2024-02-15 22:51:17 +0000
committerAda Christine <adachristine18@gmail.com>2024-02-15 22:51:17 +0000
commit0b62b5cd53c5ae58fe724db7d84d351466a161c9 (patch)
tree205b35cfe363605d531fe282ae7b2d1c6a9e6fa5 /kjarna/efi/file.c
parent96ff1a24a7474b91c44a3dcd6f3abf3ec0542191 (diff)
free resources
Diffstat (limited to 'kjarna/efi/file.c')
-rw-r--r--kjarna/efi/file.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/kjarna/efi/file.c b/kjarna/efi/file.c
index 6888390..12364e6 100644
--- a/kjarna/efi/file.c
+++ b/kjarna/efi/file.c
@@ -66,32 +66,17 @@ static void free_fd(int fd)
int efi_open(const char *path, int flags, int mode)
{
- EFI_GUID lip_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
- EFI_LOADED_IMAGE_PROTOCOL *lip = nullptr;
-
- efi_errno = gBS->OpenProtocol(
- efi_context->handle,
- &lip_guid,
- (void **)&lip,
- efi_context->handle,
- nullptr,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ static EFI_GUID lip_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
+ static EFI_GUID sfsp_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+
+ EFI_LOADED_IMAGE_PROTOCOL *lip = efi_get_protocol(efi_context->handle, &lip_guid);
if (lip == nullptr)
{
return -1;
}
- EFI_GUID sfsp_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *sfsp = nullptr;
-
- efi_errno = gBS->OpenProtocol(
- lip->DeviceHandle,
- &sfsp_guid,
- (void **)&sfsp,
- efi_context->handle,
- nullptr,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *sfsp = efi_get_protocol(lip->DeviceHandle, &sfsp_guid);
if (sfsp == nullptr)
{
@@ -117,7 +102,7 @@ int efi_open(const char *path, int flags, int mode)
size_t path_len = strlen(path) + 1;
CHAR16 *wcpath = efi_calloc_pool(path_len, sizeof(*wcpath));
- if(mbstowcs(wcpath, path, path_len) == (size_t)-1)
+ if (mbstowcs(wcpath, path, path_len) == (size_t)-1)
{
efi_errno = EFI_INVALID_PARAMETER;
}
@@ -131,6 +116,8 @@ int efi_open(const char *path, int flags, int mode)
0);
}
+ efi_close_protocol(lip->DeviceHandle, &lip_guid);
+ efi_close_protocol(efi_context->handle, &sfsp_guid);
efi_free_pool(wcpath);
(void)flags;