[U-Boot] [PATCH 07/23] efi_loader: simplify efi_install_protocol_interface

Heinrich Schuchardt xypron.glpk at gmx.de
Sat Aug 26 22:51:08 UTC 2017


Use function efi_search_obj and efi_search_protocol
to simplify the coding.

Do away with efi_install_protocol_interface_ext.
We can use EFI_CALL for internal usage.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 lib/efi_loader/efi_boottime.c | 76 ++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 45 deletions(-)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 9dae02daca..96cb1fa410 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -482,9 +482,12 @@ static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
 			efi_guid_t *protocol, int protocol_interface_type,
 			void *protocol_interface)
 {
-	struct list_head *lhandle;
 	int i;
 	efi_status_t r;
+	struct efi_object *efiobj;
+
+	EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
+		  protocol_interface);
 
 	if (!handle || !protocol ||
 	    protocol_interface_type != EFI_NATIVE_INTERFACE) {
@@ -497,54 +500,36 @@ static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
 		r = EFI_OUT_OF_RESOURCES;
 		goto out;
 	}
+
 	/* Find object. */
-	list_for_each(lhandle, &efi_obj_list) {
-		struct efi_object *efiobj;
-		efiobj = list_entry(lhandle, struct efi_object, link);
+	efiobj = efi_search_obj(*handle);
+	if (!efiobj) {
+		r = EFI_INVALID_PARAMETER;
+		goto out;
+	}
 
-		if (efiobj->handle != *handle)
-			continue;
-		/* Check if protocol is already installed on the handle. */
-		for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
-			struct efi_handler *handler = &efiobj->protocols[i];
+	/* Check if protocol is already installed on the handle. */
+	r = efi_search_protocol(*handle, protocol, NULL);
+	if (r == EFI_SUCCESS) {
+		r = EFI_INVALID_PARAMETER;
+		goto out;
+	}
 
-			if (!handler->guid)
-				continue;
-			if (!guidcmp(handler->guid, protocol)) {
-				r = EFI_INVALID_PARAMETER;
-				goto out;
-			}
-		}
-		/* Install protocol in first empty slot. */
-		for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
-			struct efi_handler *handler = &efiobj->protocols[i];
+	/* Install protocol in first empty slot. */
+	for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
+		struct efi_handler *handler = &efiobj->protocols[i];
 
-			if (handler->guid)
-				continue;
+		if (handler->guid)
+			continue;
 
-			handler->guid = protocol;
-			handler->protocol_interface = protocol_interface;
-			r = EFI_SUCCESS;
-			goto out;
-		}
-		r = EFI_OUT_OF_RESOURCES;
+		handler->guid = protocol;
+		handler->protocol_interface = protocol_interface;
+		r = EFI_SUCCESS;
 		goto out;
 	}
-	r = EFI_INVALID_PARAMETER;
+	r = EFI_OUT_OF_RESOURCES;
 out:
-	return r;
-}
-
-static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle,
-			efi_guid_t *protocol, int protocol_interface_type,
-			void *protocol_interface)
-{
-	EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
-		  protocol_interface);
-
-	return EFI_EXIT(efi_install_protocol_interface(handle, protocol,
-						       protocol_interface_type,
-						       protocol_interface));
+	return EFI_EXIT(r);
 }
 
 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
@@ -1115,9 +1100,10 @@ static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces(
 		if (!protocol)
 			break;
 		protocol_interface = va_arg(argptr, void*);
-		r = efi_install_protocol_interface(handle, protocol,
-						   EFI_NATIVE_INTERFACE,
-						   protocol_interface);
+		r = EFI_CALL(efi_install_protocol_interface(
+						handle, protocol,
+						EFI_NATIVE_INTERFACE,
+						protocol_interface));
 		if (r != EFI_SUCCESS)
 			break;
 		i++;
@@ -1263,7 +1249,7 @@ static const struct efi_boot_services efi_boot_services = {
 	.signal_event = efi_signal_event_ext,
 	.close_event = efi_close_event,
 	.check_event = efi_check_event,
-	.install_protocol_interface = efi_install_protocol_interface_ext,
+	.install_protocol_interface = efi_install_protocol_interface,
 	.reinstall_protocol_interface = efi_reinstall_protocol_interface,
 	.uninstall_protocol_interface = efi_uninstall_protocol_interface_ext,
 	.handle_protocol = efi_handle_protocol,
-- 
2.14.1



More information about the U-Boot mailing list