efi_selftest: fix memory allocation in HII tests

In efi_selftest we are in EFI land. We cannot call U-Boot library
functions malloc() and free() but should use the boot time services
instead.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Heinrich Schuchardt 2019-02-12 21:38:02 +01:00
parent afa17aa23f
commit ee3c8ba855

View file

@ -8,7 +8,6 @@
*/ */
#include <efi_selftest.h> #include <efi_selftest.h>
#include <malloc.h>
#include "efi_selftest_hii_data.c" #include "efi_selftest_hii_data.c"
#define PRINT_TESTNAME efi_st_printf("%s:\n", __func__) #define PRINT_TESTNAME efi_st_printf("%s:\n", __func__)
@ -192,9 +191,10 @@ static int test_hii_database_list_package_lists(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
handles = malloc(handles_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
if (!handles) { (void **)&handles);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_database_protocol->list_package_lists(hii_database_protocol, ret = hii_database_protocol->list_package_lists(hii_database_protocol,
@ -205,7 +205,11 @@ static int test_hii_database_list_package_lists(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
free(handles); ret = boottime->free_pool(handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
goto out;
}
/* STRINGS */ /* STRINGS */
handles = NULL; handles = NULL;
@ -219,9 +223,10 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
handles = malloc(handles_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
if (!handles) { (void **)&handles);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
@ -234,7 +239,11 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
free(handles); ret = boottime->free_pool(handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
goto out;
}
/* GUID */ /* GUID */
handles = NULL; handles = NULL;
@ -248,9 +257,10 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
handles = malloc(handles_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
if (!handles) { (void **)&handles);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
@ -263,7 +273,12 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
free(handles); ret = boottime->free_pool(handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
ret = EFI_ST_FAILURE;
goto out;
}
/* KEYBOARD_LAYOUT */ /* KEYBOARD_LAYOUT */
handles = NULL; handles = NULL;
@ -277,9 +292,10 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
handles = malloc(handles_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
if (!handles) { (void **)&handles);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
@ -292,7 +308,12 @@ static int test_hii_database_list_package_lists(void)
ret = EFI_ST_FAILURE; ret = EFI_ST_FAILURE;
goto out; goto out;
} }
free(handles); ret = boottime->free_pool(handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
ret = EFI_ST_FAILURE;
goto out;
}
result = EFI_ST_SUCCESS; result = EFI_ST_SUCCESS;
@ -398,9 +419,10 @@ static int test_hii_database_find_keyboard_layouts(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
guids = malloc(guids_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, guids_size,
if (!guids) { (void **)&guids);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_database_protocol->find_keyboard_layouts( ret = hii_database_protocol->find_keyboard_layouts(
@ -410,7 +432,11 @@ static int test_hii_database_find_keyboard_layouts(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
free(guids); ret = boottime->free_pool(guids);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
goto out;
}
result = EFI_ST_SUCCESS; result = EFI_ST_SUCCESS;
@ -479,9 +505,10 @@ static int test_hii_database_get_keyboard_layout(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
kb_layout = malloc(kb_layout_size); ret = boottime->allocate_pool(EFI_LOADER_DATA, kb_layout_size,
if (!kb_layout) { (void **)&kb_layout);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_database_protocol->get_keyboard_layout(hii_database_protocol, ret = hii_database_protocol->get_keyboard_layout(hii_database_protocol,
@ -491,7 +518,11 @@ static int test_hii_database_get_keyboard_layout(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
free(kb_layout); ret = boottime->free_pool(kb_layout);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
goto out;
}
/* current */ /* current */
kb_layout = NULL; kb_layout = NULL;
@ -738,9 +769,10 @@ static int test_hii_string_get_string(void)
goto out; goto out;
} }
string_len += sizeof(u16); string_len += sizeof(u16);
string = malloc(string_len); ret = boottime->allocate_pool(EFI_LOADER_DATA, string_len,
if (!string) { (void **)&string);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_string_protocol->get_string(hii_string_protocol, ret = hii_string_protocol->get_string(hii_string_protocol,
@ -875,9 +907,10 @@ static int test_hii_string_get_languages(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
languages = malloc(languages_len); ret = boottime->allocate_pool(EFI_LOADER_DATA, languages_len,
if (!languages) { (void **)&languages);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_string_protocol->get_languages(hii_string_protocol, handle, ret = hii_string_protocol->get_languages(hii_string_protocol, handle,
@ -947,9 +980,10 @@ static int test_hii_string_get_secondary_languages(void)
(unsigned int)ret); (unsigned int)ret);
goto out; goto out;
} }
languages = malloc(languages_len); ret = boottime->allocate_pool(EFI_LOADER_DATA, languages_len,
if (!languages) { (void **)&languages);
efi_st_error("malloc failed\n"); if (ret != EFI_SUCCESS) {
efi_st_error("AllocatePool failed\n");
goto out; goto out;
} }
ret = hii_string_protocol->get_secondary_languages(hii_string_protocol, ret = hii_string_protocol->get_secondary_languages(hii_string_protocol,