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>
---
 include/efi_loader.h              |  6 ++----
 lib/efi_loader/net/efi_http.c     | 20 +++++++++++++-------
 lib/efi_loader/net/efi_ipconfig.c | 19 ++++++++++++-------
 lib/efi_loader/net/efi_net.c      | 26 ++++++++++++++------------
 4 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 84e8cfe320e..5c1244824f3 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -662,11 +662,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..536ce1edb97 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,25 +483,30 @@ 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_allocate_pool(EFI_LOADER_DATA,
+                             sizeof(*http_service_binding),
+                             (void **)&http_service_binding);
+       if (r != EFI_SUCCESS)
+               return r;
 
        r = efi_add_protocol(handle, &efi_http_service_binding_guid,
                             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:
-       return r;
 }
 
 enum efi_http_status_code efi_u32_to_httpstatus(u32 status)
diff --git a/lib/efi_loader/net/efi_ipconfig.c 
b/lib/efi_loader/net/efi_ipconfig.c
index 9f51f77fa9a..a46cba09f01 100644
--- a/lib/efi_loader/net/efi_ipconfig.c
+++ b/lib/efi_loader/net/efi_ipconfig.c
@@ -190,20 +190,25 @@ 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_allocate_pool(EFI_LOADER_DATA,
+                             sizeof(*ip4config),
+                             (void **)&ip4config);
+       if (r != EFI_SUCCESS)
+               return r;
 
        r = efi_add_protocol(handle, &efi_ip4_config2_guid,
                             ip4config);
-       if (r != EFI_SUCCESS) {
-               log_err("ERROR: Failure to add protocol\n");
+       if (r != EFI_SUCCESS)
                return r;
-       }
 
        memcpy(current_mac_addr, eth_get_ethaddr(), 6);
 
diff --git a/lib/efi_loader/net/efi_net.c b/lib/efi_loader/net/efi_net.c
index b3291b4f1d5..40db80f4726 100644
--- a/lib/efi_loader/net/efi_net.c
+++ b/lib/efi_loader/net/efi_net.c
@@ -31,6 +31,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;
@@ -73,8 +75,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
@@ -92,12 +92,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;
@@ -1285,13 +1279,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
@@ -1645,6 +1638,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)
@@ -1656,8 +1650,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

Reply via email to