efi_net.c should only [un]install protocols, leaving the actual implementation to efi_http.c and efi_ipconfig.c
Signed-off-by: Adriano Cordova <adriano.cord...@canonical.com> --- Changes in v2: - free protocol interfaces if protocol installation fails include/efi_loader.h | 6 ++---- lib/efi_loader/net/efi_http.c | 24 +++++++++++++++--------- lib/efi_loader/net/efi_ipconfig.c | 25 +++++++++++++++---------- lib/efi_loader/net/efi_net.c | 26 ++++++++++++++------------ 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index b3beda5de7b..fd8ae599ced 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -682,11 +682,9 @@ efi_status_t efi_gop_register(void); efi_status_t efi_net_register(struct udevice *dev); efi_status_t efi_net_do_start(struct udevice *dev); /* Called by efi_net_register to make the ip4 config2 protocol available */ -efi_status_t efi_ipconfig_register(const efi_handle_t handle, - struct efi_ip4_config2_protocol *ip4config); +efi_status_t efi_ip4_config2_install(const efi_handle_t handle); /* Called by efi_net_register to make the http protocol available */ -efi_status_t efi_http_register(const efi_handle_t handle, - struct efi_service_binding_protocol *http_service_binding); +efi_status_t efi_http_install(const efi_handle_t handle); /* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register(void); efi_status_t efi_initrd_register(struct efi_device_path *dp_initrd); diff --git a/lib/efi_loader/net/efi_http.c b/lib/efi_loader/net/efi_http.c index 189317fe2d2..709167a2a25 100644 --- a/lib/efi_loader/net/efi_http.c +++ b/lib/efi_loader/net/efi_http.c @@ -24,6 +24,7 @@ static const efi_guid_t efi_http_guid = EFI_HTTP_PROTOCOL_GUID; * * @http: EFI_HTTP_PROTOCOL interface * @handle: handle to efi object + * @parent: service binding that created this child * @configured: configuration status * @http_load_addr: data buffer * @file_size: size of data @@ -391,7 +392,7 @@ static efi_status_t EFIAPI efi_http_service_binding_create_child( if (!child_handle) return EFI_EXIT(EFI_INVALID_PARAMETER); - new_instance = calloc(1, sizeof(struct efi_http_instance)); + new_instance = calloc(1, sizeof(*new_instance)); if (!new_instance) { ret = EFI_OUT_OF_RESOURCES; goto failure_to_add_protocol; @@ -482,24 +483,29 @@ static efi_status_t EFIAPI efi_http_service_binding_destroy_child( } /** - * efi_http_register() - register the http protocol + * efi_http_install() - install the EFI_HTTP_SERVICE_BINDING_PROTOCOL * + * @handle: handle to install the protocol */ -efi_status_t efi_http_register(const efi_handle_t handle, - struct efi_service_binding_protocol *http_service_binding) +efi_status_t efi_http_install(const efi_handle_t handle) { efi_status_t r = EFI_SUCCESS; + struct efi_service_binding_protocol *http_service_binding; - r = efi_add_protocol(handle, &efi_http_service_binding_guid, - http_service_binding); + r = efi_allocate_pool(EFI_LOADER_DATA, + sizeof(*http_service_binding), + (void **)&http_service_binding); if (r != EFI_SUCCESS) - goto failure_to_add_protocol; + return r; http_service_binding->create_child = efi_http_service_binding_create_child; http_service_binding->destroy_child = efi_http_service_binding_destroy_child; - return EFI_SUCCESS; -failure_to_add_protocol: + r = efi_add_protocol(handle, &efi_http_service_binding_guid, + http_service_binding); + if (r != EFI_SUCCESS) + efi_free_pool(http_service_binding); + return r; } diff --git a/lib/efi_loader/net/efi_ipconfig.c b/lib/efi_loader/net/efi_ipconfig.c index 9f51f77fa9a..7e18026cfea 100644 --- a/lib/efi_loader/net/efi_ipconfig.c +++ b/lib/efi_loader/net/efi_ipconfig.c @@ -190,20 +190,20 @@ static efi_status_t EFIAPI efi_ip4_config2_unregister_notify(struct efi_ip4_conf } /** - * efi_ipconfig_register() - register the ip4_config2 protocol + * efi_ip4_config2_install() - install the EFI_IP4_CONFIG2_PROTOCOL * + * @handle handle to install the protocol */ -efi_status_t efi_ipconfig_register(const efi_handle_t handle, - struct efi_ip4_config2_protocol *ip4config) +efi_status_t efi_ip4_config2_install(const efi_handle_t handle) { - efi_status_t r = EFI_SUCCESS; + efi_status_t r; + struct efi_ip4_config2_protocol *ip4config; - r = efi_add_protocol(handle, &efi_ip4_config2_guid, - ip4config); - if (r != EFI_SUCCESS) { - log_err("ERROR: Failure to add protocol\n"); + r = efi_allocate_pool(EFI_LOADER_DATA, + sizeof(*ip4config), + (void **)&ip4config); + if (r != EFI_SUCCESS) return r; - } memcpy(current_mac_addr, eth_get_ethaddr(), 6); @@ -212,5 +212,10 @@ efi_status_t efi_ipconfig_register(const efi_handle_t handle, ip4config->register_data_notify = efi_ip4_config2_register_notify; ip4config->unregister_data_notify = efi_ip4_config2_unregister_notify; - return EFI_SUCCESS; + r = efi_add_protocol(handle, &efi_ip4_config2_guid, + ip4config); + if (r != EFI_SUCCESS) + efi_free_pool(ip4config); + + return r; } diff --git a/lib/efi_loader/net/efi_net.c b/lib/efi_loader/net/efi_net.c index 8e708d8d350..387bfec7cb2 100644 --- a/lib/efi_loader/net/efi_net.c +++ b/lib/efi_loader/net/efi_net.c @@ -32,6 +32,8 @@ const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; static const efi_guid_t efi_pxe_base_code_protocol_guid = EFI_PXE_BASE_CODE_PROTOCOL_GUID; +static const efi_guid_t efi_http_service_binding_guid = + EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID; struct dp_entry { struct efi_device_path *net_dp; @@ -74,8 +76,6 @@ static int next_dhcp_entry; * @net_mode: status of the network interface * @pxe: PXE base code protocol interface * @pxe_mode: status of the PXE base code protocol - * @ip4_config2: IP4 Config2 protocol interface - * @http_service_binding: Http service binding protocol interface * @new_tx_packet: new transmit packet * @transmit_buffer: transmit buffer * @receive_buffer: array of receive buffers @@ -93,12 +93,6 @@ struct efi_net_obj { struct efi_simple_network_mode net_mode; struct efi_pxe_base_code_protocol pxe; struct efi_pxe_mode pxe_mode; -#if IS_ENABLED(CONFIG_EFI_IP4_CONFIG2_PROTOCOL) - struct efi_ip4_config2_protocol ip4_config2; -#endif -#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL) - struct efi_service_binding_protocol http_service_binding; -#endif void *new_tx_packet; void *transmit_buffer; uchar **receive_buffer; @@ -1286,13 +1280,12 @@ efi_status_t efi_net_register(struct udevice *dev) } #if IS_ENABLED(CONFIG_EFI_IP4_CONFIG2_PROTOCOL) - r = efi_ipconfig_register(&netobj->header, &netobj->ip4_config2); + r = efi_ip4_config2_install(&netobj->header); if (r != EFI_SUCCESS) goto failure_to_add_protocol; #endif - #ifdef CONFIG_EFI_HTTP_PROTOCOL - r = efi_http_register(&netobj->header, &netobj->http_service_binding); + r = efi_http_install(&netobj->header); if (r != EFI_SUCCESS) goto failure_to_add_protocol; #endif @@ -1646,6 +1639,7 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf int wget_ret; static bool last_head; struct udevice *dev; + struct efi_handler *phandler; int i; if (!buffer || !file_size || !parent) @@ -1657,8 +1651,16 @@ efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buf // Set corresponding udevice dev = NULL; for (i = 0; i < MAX_EFI_NET_OBJS; i++) { - if (net_objs[i] && &net_objs[i]->http_service_binding == parent) + if (!net_objs[i]) + continue; + + ret = efi_search_protocol(&net_objs[i]->header, + &efi_http_service_binding_guid, + &phandler); + if (ret == EFI_SUCCESS && phandler == (void *)parent) { dev = net_objs[i]->dev; + break; + } } if (!dev) return EFI_ABORTED; -- 2.48.1