efi_loader: typedef struct efi_object *efi_handle_t

All our handles point to a struct efi_object. So let's define the
efi_handle_t accordingly. This helps us to discover coding errors much
more easily. This becomes evident by the corrections to the usage of
handles in this patch.

Rename variable image_handle to image_obj where applicable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Heinrich Schuchardt 2018-09-26 05:27:54 +02:00 committed by Alexander Graf
parent d8b2216c87
commit faea104105
6 changed files with 30 additions and 30 deletions

View file

@ -345,7 +345,7 @@ static efi_status_t do_bootefi_exec(void *efi,
efi_handle_t mem_handle = NULL; efi_handle_t mem_handle = NULL;
struct efi_device_path *memdp = NULL; struct efi_device_path *memdp = NULL;
efi_status_t ret; efi_status_t ret;
struct efi_loaded_image_obj *image_handle = NULL; struct efi_loaded_image_obj *image_obj = NULL;
struct efi_loaded_image *loaded_image_info = NULL; struct efi_loaded_image *loaded_image_info = NULL;
EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
@ -376,7 +376,7 @@ static efi_status_t do_bootefi_exec(void *efi,
assert(device_path && image_path); assert(device_path && image_path);
} }
ret = efi_setup_loaded_image(device_path, image_path, &image_handle, ret = efi_setup_loaded_image(device_path, image_path, &image_obj,
&loaded_image_info); &loaded_image_info);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
goto exit; goto exit;
@ -384,7 +384,7 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Transfer environment variable bootargs as load options */ /* Transfer environment variable bootargs as load options */
set_load_options(loaded_image_info, "bootargs"); set_load_options(loaded_image_info, "bootargs");
/* Load the EFI payload */ /* Load the EFI payload */
entry = efi_load_pe(image_handle, efi, loaded_image_info); entry = efi_load_pe(image_obj, efi, loaded_image_info);
if (!entry) { if (!entry) {
ret = EFI_LOAD_ERROR; ret = EFI_LOAD_ERROR;
goto exit; goto exit;
@ -405,8 +405,8 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Call our payload! */ /* Call our payload! */
debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry); debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
if (setjmp(&image_handle->exit_jmp)) { if (setjmp(&image_obj->exit_jmp)) {
ret = image_handle->exit_status; ret = image_obj->exit_status;
goto exit; goto exit;
} }
@ -418,7 +418,7 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Move into EL2 and keep running there */ /* Move into EL2 and keep running there */
armv8_switch_to_el2((ulong)entry, armv8_switch_to_el2((ulong)entry,
(ulong)image_handle, (ulong)&image_obj->parent,
(ulong)&systab, 0, (ulong)efi_run_in_el2, (ulong)&systab, 0, (ulong)efi_run_in_el2,
ES_TO_AARCH64); ES_TO_AARCH64);
@ -435,7 +435,7 @@ static efi_status_t do_bootefi_exec(void *efi,
secure_ram_addr(_do_nonsec_entry)( secure_ram_addr(_do_nonsec_entry)(
efi_run_in_hyp, efi_run_in_hyp,
(uintptr_t)entry, (uintptr_t)entry,
(uintptr_t)image_handle, (uintptr_t)&image_obj->parent,
(uintptr_t)&systab); (uintptr_t)&systab);
/* Should never reach here, efi exits with longjmp */ /* Should never reach here, efi exits with longjmp */
@ -443,12 +443,12 @@ static efi_status_t do_bootefi_exec(void *efi,
} }
#endif #endif
ret = efi_do_enter(image_handle, &systab, entry); ret = efi_do_enter(&image_obj->parent, &systab, entry);
exit: exit:
/* image has returned, loaded-image obj goes *poof*: */ /* image has returned, loaded-image obj goes *poof*: */
if (image_handle) if (image_obj)
efi_delete_handle(&image_handle->parent); efi_delete_handle(&image_obj->parent);
if (mem_handle) if (mem_handle)
efi_delete_handle(mem_handle); efi_delete_handle(mem_handle);
@ -527,7 +527,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#endif #endif
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
if (!strcmp(argv[1], "selftest")) { if (!strcmp(argv[1], "selftest")) {
struct efi_loaded_image_obj *image_handle; struct efi_loaded_image_obj *image_obj;
struct efi_loaded_image *loaded_image_info; struct efi_loaded_image *loaded_image_info;
/* Construct a dummy device path. */ /* Construct a dummy device path. */
@ -537,7 +537,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest"); bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
r = efi_setup_loaded_image(bootefi_device_path, r = efi_setup_loaded_image(bootefi_device_path,
bootefi_image_path, &image_handle, bootefi_image_path, &image_obj,
&loaded_image_info); &loaded_image_info);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
@ -546,10 +546,10 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* Transfer environment variable efi_selftest as load options */ /* Transfer environment variable efi_selftest as load options */
set_load_options(loaded_image_info, "efi_selftest"); set_load_options(loaded_image_info, "efi_selftest");
/* Execute the test */ /* Execute the test */
r = efi_selftest(image_handle, &systab); r = efi_selftest(&image_obj->parent, &systab);
efi_restore_gd(); efi_restore_gd();
free(loaded_image_info->load_options); free(loaded_image_info->load_options);
efi_delete_handle(&image_handle->parent); efi_delete_handle(&image_obj->parent);
return r != EFI_SUCCESS; return r != EFI_SUCCESS;
} else } else
#endif #endif

View file

@ -96,7 +96,7 @@ typedef struct {
typedef unsigned long efi_status_t; typedef unsigned long efi_status_t;
typedef u64 efi_physical_addr_t; typedef u64 efi_physical_addr_t;
typedef u64 efi_virtual_addr_t; typedef u64 efi_virtual_addr_t;
typedef void *efi_handle_t; typedef struct efi_object *efi_handle_t;
#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \ {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \

View file

@ -85,10 +85,10 @@ struct efi_boot_services {
efi_status_t (EFIAPI *check_event)(struct efi_event *event); efi_status_t (EFIAPI *check_event)(struct efi_event *event);
#define EFI_NATIVE_INTERFACE 0x00000000 #define EFI_NATIVE_INTERFACE 0x00000000
efi_status_t (EFIAPI *install_protocol_interface)( efi_status_t (EFIAPI *install_protocol_interface)(
void **handle, const efi_guid_t *protocol, efi_handle_t *handle, const efi_guid_t *protocol,
int protocol_interface_type, void *protocol_interface); int protocol_interface_type, void *protocol_interface);
efi_status_t (EFIAPI *reinstall_protocol_interface)( efi_status_t (EFIAPI *reinstall_protocol_interface)(
void *handle, const efi_guid_t *protocol, efi_handle_t handle, const efi_guid_t *protocol,
void *old_interface, void *new_interface); void *old_interface, void *new_interface);
efi_status_t (EFIAPI *uninstall_protocol_interface)( efi_status_t (EFIAPI *uninstall_protocol_interface)(
efi_handle_t handle, const efi_guid_t *protocol, efi_handle_t handle, const efi_guid_t *protocol,
@ -164,9 +164,9 @@ struct efi_boot_services {
efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol, efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
void *registration, void **protocol_interface); void *registration, void **protocol_interface);
efi_status_t (EFIAPI *install_multiple_protocol_interfaces)( efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
void **handle, ...); efi_handle_t *handle, ...);
efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)( efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(
void *handle, ...); efi_handle_t handle, ...);
efi_status_t (EFIAPI *calculate_crc32)(const void *data, efi_status_t (EFIAPI *calculate_crc32)(const void *data,
efi_uintn_t data_size, efi_uintn_t data_size,
u32 *crc32); u32 *crc32);

View file

@ -69,7 +69,7 @@ int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
efi_putc(priv, ' '); efi_putc(priv, ' ');
ret = boot->open_protocol(priv->parent_image, &loaded_image_guid, ret = boot->open_protocol(priv->parent_image, &loaded_image_guid,
(void **)&loaded_image, &priv->parent_image, (void **)&loaded_image, priv->parent_image,
NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (ret) { if (ret) {
efi_puts(priv, "Failed to get loaded image protocol\n"); efi_puts(priv, "Failed to get loaded image protocol\n");

View file

@ -1019,7 +1019,7 @@ efi_status_t efi_add_protocol(const efi_handle_t handle,
* Return: status code * Return: status code
*/ */
static efi_status_t EFIAPI efi_install_protocol_interface( static efi_status_t EFIAPI efi_install_protocol_interface(
void **handle, const efi_guid_t *protocol, efi_handle_t *handle, const efi_guid_t *protocol,
int protocol_interface_type, void *protocol_interface) int protocol_interface_type, void *protocol_interface)
{ {
efi_status_t r; efi_status_t r;
@ -2309,8 +2309,8 @@ out:
* *
* Return: status code * Return: status code
*/ */
static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces
void **handle, ...) (efi_handle_t *handle, ...)
{ {
EFI_ENTRY("%p", handle); EFI_ENTRY("%p", handle);
@ -2346,7 +2346,7 @@ static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
for (; i; --i) { for (; i; --i) {
protocol = efi_va_arg(argptr, efi_guid_t*); protocol = efi_va_arg(argptr, efi_guid_t*);
protocol_interface = efi_va_arg(argptr, void*); protocol_interface = efi_va_arg(argptr, void*);
EFI_CALL(efi_uninstall_protocol_interface(handle, protocol, EFI_CALL(efi_uninstall_protocol_interface(*handle, protocol,
protocol_interface)); protocol_interface));
} }
efi_va_end(argptr); efi_va_end(argptr);
@ -2369,7 +2369,7 @@ static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
* Return: status code * Return: status code
*/ */
static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces(
void *handle, ...) efi_handle_t handle, ...)
{ {
EFI_ENTRY("%p", handle); EFI_ENTRY("%p", handle);
@ -2588,10 +2588,10 @@ out:
* *
* Return: status code * Return: status code
*/ */
static efi_status_t EFIAPI efi_open_protocol( static efi_status_t EFIAPI efi_open_protocol
void *handle, const efi_guid_t *protocol, (efi_handle_t handle, const efi_guid_t *protocol,
void **protocol_interface, void *agent_handle, void **protocol_interface, efi_handle_t agent_handle,
void *controller_handle, uint32_t attributes) efi_handle_t controller_handle, uint32_t attributes)
{ {
struct efi_handler *handler; struct efi_handler *handler;
efi_status_t r = EFI_INVALID_PARAMETER; efi_status_t r = EFI_INVALID_PARAMETER;

View file

@ -257,7 +257,7 @@ static int teardown(void)
static int execute(void) static int execute(void)
{ {
struct efi_device_path *remaining_dp; struct efi_device_path *remaining_dp;
void *handle; efi_handle_t handle;
/* /*
* This device path node ends with the letter 't' of 'u-boot'. * This device path node ends with the letter 't' of 'u-boot'.
* The following '.bin' does not belong to the node but is * The following '.bin' does not belong to the node but is