On 11/08/2017 04:43 PM, Alexander Graf wrote:
On 11/01/2017 09:31 AM, Heinrich Schuchardt wrote:
Signed-off-by: Heinrich Schuchardt
---
include/efi_loader.h | 6 ++-
lib/efi_loader/efi_boottime.c | 107
--
lib/efi_loader/efi_disk.c | 1 +
lib/efi_loader/efi_gop.c | 1 +
lib/efi_loader/efi_net.c | 1 +
5 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/include/efi_loader.h b/include/efi_loader.h
index e1f0af3496..a73bbc1269 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -101,6 +101,8 @@ extern unsigned int __efi_runtime_rel_start,
__efi_runtime_rel_stop;
* interface (usually a struct with callback functions), this struct
maps the
* protocol GUID to the respective protocol interface */
struct efi_handler {
+ /* Link to the list of protocols of a handle */
+ struct list_head link;
const efi_guid_t *guid;
void *protocol_interface;
};
@@ -115,8 +117,8 @@ struct efi_handler {
struct efi_object {
/* Every UEFI object is part of a global object list */
struct list_head link;
- /* We support up to 16 "protocols" an object can be accessed
through */
- struct efi_handler protocols[16];
+ /* The list of protocols */
+ struct list_head protocols;
/* The object spawner can either use this for data or as
identifier */
void *handle;
};
diff --git a/lib/efi_loader/efi_boottime.c
b/lib/efi_loader/efi_boottime.c
index 2b3db162a1..cee0cb1390 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -339,6 +339,7 @@ efi_status_t efi_create_handle(void **handle)
return r;
memset(obj, 0, sizeof(struct efi_object));
obj->handle = obj;
+ INIT_LIST_HEAD(>protocols);
list_add_tail(>link, _obj_list);
*handle = obj;
return r;
@@ -715,18 +716,17 @@ efi_status_t efi_search_protocol(const void
*handle,
struct efi_handler **handler)
{
struct efi_object *efiobj;
- size_t i;
- struct efi_handler *protocol;
+ struct list_head *lhandle;
if (!handle || !protocol_guid)
return EFI_INVALID_PARAMETER;
efiobj = efi_search_obj(handle);
if (!efiobj)
return EFI_INVALID_PARAMETER;
- for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
- protocol = >protocols[i];
- if (!protocol->guid)
- continue;
+ list_for_each(lhandle, >protocols) {
+ struct efi_handler *protocol;
+
+ protocol = list_entry(lhandle, struct efi_handler, link);
if (!guidcmp(protocol->guid, protocol_guid)) {
if (handler)
*handler = protocol;
@@ -750,7 +750,6 @@ efi_status_t efi_add_protocol(const void *handle,
const efi_guid_t *protocol,
struct efi_object *efiobj;
struct efi_handler *handler;
efi_status_t ret;
- size_t i;
efiobj = efi_search_obj(handle);
if (!efiobj)
@@ -761,16 +760,10 @@ efi_status_t efi_add_protocol(const void
*handle, const efi_guid_t *protocol,
handler = calloc(1, sizeof(struct efi_handler));
if (!handler)
return EFI_OUT_OF_RESOURCES;
- /* Install protocol in first empty slot. */
- for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
- handler = >protocols[i];
- if (handler->guid)
- continue;
- handler->guid = protocol;
- handler->protocol_interface = protocol_interface;
- return EFI_SUCCESS;
- }
- return EFI_OUT_OF_RESOURCES;
+ handler->guid = protocol;
+ handler->protocol_interface = protocol_interface;
+ list_add_tail(>link, >protocols);
+ return EFI_SUCCESS;
}
/*
@@ -790,10 +783,10 @@ efi_status_t efi_remove_protocol(const void
*handle, const efi_guid_t *protocol,
ret = efi_search_protocol(handle, protocol, );
if (ret != EFI_SUCCESS)
return ret;
- if (handler->protocol_interface != protocol_interface)
- return EFI_NOT_FOUND;
- handler->guid = NULL;
- handler->protocol_interface = NULL;
+ if (guidcmp(handler->guid, protocol))
+ return EFI_INVALID_PARAMETER;
+ list_del(>link);
+ free(handler);
return EFI_SUCCESS;
}
@@ -806,17 +799,22 @@ efi_status_t efi_remove_protocol(const void
*handle, const efi_guid_t *protocol,
efi_status_t efi_remove_all_protocols(const void *handle)
{
struct efi_object *efiobj;
- struct efi_handler *handler;
- size_t i;
+ struct list_head *lhandle;
+ struct list_head *pos;
efiobj = efi_search_obj(handle);
if (!efiobj)
return EFI_INVALID_PARAMETER;
+ list_for_each_safe(lhandle, pos, >protocols) {
+ struct efi_handler *protocol;
+ efi_status_t ret;
- for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
- handler = >protocols[i];
- handler->guid = NULL;
- handler->protocol_interface = NULL;
+ protocol =