efi_loader: simplify protocol installation
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 12 Apr 2019 05:14:43 +0000 (07:14 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 12 Apr 2019 20:00:42 +0000 (22:00 +0200)
By using InstallMultipleProtocolInterfaces() the coding for installing
protocol interfaces on the root node can be simplified.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
lib/efi_loader/efi_root_node.c

index b58d9d8c96f887f527c78c0a5d2e9f2485a8346e..392f5c49513d9874fdef858c118aa9fcd0d281cc 100644 (file)
@@ -26,16 +26,10 @@ struct efi_root_dp {
  */
 efi_status_t efi_root_node_register(void)
 {
-       efi_handle_t root;
-       efi_status_t ret;
+       efi_handle_t root = NULL;
        struct efi_root_dp *dp;
 
-       /* Create handle */
-       ret = efi_create_handle(&root);
-       if (ret != EFI_SUCCESS)
-               return ret;
-
-       /* Install device path protocol */
+       /* Create device path protocol */
        dp = calloc(1, sizeof(*dp));
        if (!dp)
                return EFI_OUT_OF_RESOURCES;
@@ -51,49 +45,29 @@ efi_status_t efi_root_node_register(void)
        dp->end.sub_type = DEVICE_PATH_SUB_TYPE_END;
        dp->end.length = sizeof(struct efi_device_path);
 
-       /* Install device path protocol */
-       ret = efi_add_protocol(root, &efi_guid_device_path, dp);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
-       /* Install device path to text protocol */
-       ret = efi_add_protocol(root, &efi_guid_device_path_to_text_protocol,
-                              (void *)&efi_device_path_to_text);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
-       /* Install device path utilities protocol */
-       ret = efi_add_protocol(root, &efi_guid_device_path_utilities_protocol,
-                              (void *)&efi_device_path_utilities);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
-       /* Install Unicode collation protocol */
-       ret = efi_add_protocol(root, &efi_guid_unicode_collation_protocol,
-                              (void *)&efi_unicode_collation_protocol);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
+       /* Create root node and install protocols */
+       return EFI_CALL(efi_install_multiple_protocol_interfaces(&root,
+                      /* Device path protocol */
+                      &efi_guid_device_path, dp,
+                      /* Device path to text protocol */
+                      &efi_guid_device_path_to_text_protocol,
+                      (void *)&efi_device_path_to_text,
+                      /* Device path utilities protocol */
+                      &efi_guid_device_path_utilities_protocol,
+                      (void *)&efi_device_path_utilities,
+                      /* Unicode collation protocol */
+                      &efi_guid_unicode_collation_protocol,
+                      (void *)&efi_unicode_collation_protocol,
 #if CONFIG_IS_ENABLED(EFI_LOADER_HII)
-       /* Install HII string protocol */
-       ret = efi_add_protocol(root, &efi_guid_hii_string_protocol,
-                              (void *)&efi_hii_string);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
-       /* Install HII database protocol */
-       ret = efi_add_protocol(root, &efi_guid_hii_database_protocol,
-                              (void *)&efi_hii_database);
-       if (ret != EFI_SUCCESS)
-               goto failure;
-
-       /* Install HII configuration routing protocol */
-       ret = efi_add_protocol(root, &efi_guid_hii_config_routing_protocol,
-                              (void *)&efi_hii_config_routing);
-       if (ret != EFI_SUCCESS)
-               goto failure;
+                      /* HII string protocol */
+                      &efi_guid_hii_string_protocol,
+                      (void *)&efi_hii_string,
+                      /* HII database protocol */
+                      &efi_guid_hii_database_protocol,
+                      (void *)&efi_hii_database,
+                      /* HII configuration routing protocol */
+                      &efi_guid_hii_config_routing_protocol,
+                      (void *)&efi_hii_config_routing,
 #endif
-
-failure:
-       return ret;
+                      NULL));
 }