From patchwork Thu Oct 6 19:40:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 612924 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp435483pvb; Thu, 6 Oct 2022 12:40:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43BwmTs/7XwW9JR3ZzyRC8kEP1rlS7VuS4bOHpl+T0bERTWgK5iU4NnwK+jUO0F8q+eA20 X-Received: by 2002:a17:907:a047:b0:78d:3ac7:ed73 with SMTP id gz7-20020a170907a04700b0078d3ac7ed73mr1219024ejc.237.1665085253287; Thu, 06 Oct 2022 12:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665085253; cv=none; d=google.com; s=arc-20160816; b=kn4Fl4/RX5aXbcvRsrun2d+YsnX6dhX4RGiIxYKo1xrhMvG1D7Qne4Bi8bY2r1tBEE hHqYmeFyqQ5rrNKeSONgQcTPuSAsfKyDfQYWrEZdUQjSVcfDdmhcZ4ZVJ8BBAc4fPe4z tlR95751RZ1OybQEJ69aN5sLJMcHYUEmMhmdJlgzLkBun3sodiSAi16EpcooZjc8b7t7 WKBiwHfC40mp6Mc+uUcDKYItZ1efsDYmQRLzMaAe8stXWTvf6qMiH8j5TjWWbp+1hvKg dsC4UqojjcP9nkCn8tFZU4Lskpy+cAr7JjLJpKIb8+KOf6cBluu2LGgKfzPpq3rjqw6w t47w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d0bLi8+y6ErD34HbyhlKrRTDlfDcsORGXixmc+OgUIo=; b=KYf0/rljtz3/HMMzrEQ593K/alfTYI/tL7AddoyPEZcleYgib6OowPADpTF8hdEZbr b3av9ovCl9SOQ0ouOj/q6kjkbTWi0PPZ3Mkgpke+r3KbLQq3+anyVF7Me6iXTfyVRCb3 xLn0D0jD5VlP1Czibe9nwU6Ms9Q8jo8WSeIuc+jxZJPHmytcQCZ0l7hX3ejHunoV9fXy PQYP33t+zeDNixD8KBOQ/HpqEXMRFLfoK2rW4t33E0twjMtxApFQy2J9Td9QAxJRmksa 0Hvn8pUL7Vy8+krsIW9XgUFP6BXktb016p1GpQ5dXCeyq6H1Eh8EQpEJ9HKeO4ehrVCX uRpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Yhh/dv2E"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i2-20020a50fc02000000b00459141c6f75si120207edr.100.2022.10.06.12.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 12:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Yhh/dv2E"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EA6384DB6; Thu, 6 Oct 2022 21:40:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Yhh/dv2E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3DB4E84DAA; Thu, 6 Oct 2022 21:40:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2176F84D2B for ; Thu, 6 Oct 2022 21:40:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x52d.google.com with SMTP id u21so4268802edi.9 for ; Thu, 06 Oct 2022 12:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=d0bLi8+y6ErD34HbyhlKrRTDlfDcsORGXixmc+OgUIo=; b=Yhh/dv2EcHYZf1PZfYNtdsoURpqzgo5sVVBU3PW2Vy+OfgiChV5azg8Nvn35kjg0wZ u/N7uL+Nzcea7vNjJhPFUItXGyX6upPjhAVZdwhziBrC34aEd0Qg2F6KZhJXK/rE3eHA DvTK+VANwM28LG1Js5R97OjL2i8tiH0fXTZ2DQf1g/pwtQf7qupR+dqAHhTQIR7YBfBL dVYDPVknJNgUITE2dFsRqdpnfkJSwtbtFha/IFfAbx85ERzTJlpIWcPBqvdTFcLgXfwf 5HfqJBfGfZ+eHwiU3zcorUAq5C9o6ntzMF16F0ex0JAoujQdwd1wbHe2sz+Ibng0Dg84 SRyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=d0bLi8+y6ErD34HbyhlKrRTDlfDcsORGXixmc+OgUIo=; b=MUFr4sKg0IrIcKlQk7va1aOESyPVkDNzEGH9ekyK/9eIMCb1O7ecC8SZa8NfxFH/tQ zf0t8g3VmP1eqL9Dg6ZfCx2EHNbZR/QWIeYiMoT7IPBPKRJSc9zuXGeMCCN8psVU6vaa t8B4vjPkCD3E+KEubHwcR/LWEAlgTrjuUj5u3YI64WSlL2my/ndD7wQDVpf5SRqi9OyB Ymt0uQeuzhGgwfiBK5UgukNmK1eV7KIVDyAkJdCuQ0R9bqcDOwtmfT1e4QA55wS5Fwed cskWJilV/lSotGSbB+8F/+qzF1128lWp6yaHx567yEB4ccbmpxSO8Fn54CLSygHG5iwS 4PLw== X-Gm-Message-State: ACrzQf26aOwlGK3GW7rIqb3pv5sTmdW+OCfoBOiRcid0qO5KtHH1+ovv ZEFG2hd+nJPp9D3VG64PAeFnig== X-Received: by 2002:a05:6402:170f:b0:458:9653:6466 with SMTP id y15-20020a056402170f00b0045896536466mr1318001edu.181.1665085234611; Thu, 06 Oct 2022 12:40:34 -0700 (PDT) Received: from hades.. (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id bo1-20020a170906d04100b0077b2b0563f4sm99147ejb.173.2022.10.06.12.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 12:40:34 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , u-boot@lists.denx.de Subject: [PATCH 1/2 v2] efi_loader: define internal implementations of install/uninstallmultiple Date: Thu, 6 Oct 2022 22:40:23 +0300 Message-Id: <20221006194028.28358-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221006194028.28358-1-ilias.apalodimas@linaro.org> References: <20221006194028.28358-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean A following patch is cleaning up the core EFI code trying to remove sequences of efi_create_handle, efi_add_protocol. Although this works fine there's a problem with the latter since it is usually combined with efi_delete_handle() which blindly removes all protocols on a handle and deletes the handle. We should try to adhere to the EFI spec which only deletes a handle if the last instance of a protocol has been removed. Another problem is that efi_delete_handle() never checks for opened protocols, but the EFI spec defines that the caller is responsible for ensuring that there are no references to a protocol interface that is going to be removed. So let's fix this by replacing all callsites of efi_create_handle(), efi_add_protocol() , efi_delete_handle() with Install/UninstallMultipleProtocol. In order to do that redefine functions that can be used by the U-Boot proper internally and add '_ext' variants that will be used from the EFI API Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- include/efi.h | 2 + include/efi_loader.h | 6 +- lib/efi_loader/efi_boottime.c | 214 +++++++++++++++++++++++-------- lib/efi_loader/efi_capsule.c | 15 ++- lib/efi_loader/efi_console.c | 14 +- lib/efi_loader/efi_disk.c | 10 +- lib/efi_loader/efi_load_initrd.c | 15 +-- lib/efi_loader/efi_root_node.c | 48 +++---- 8 files changed, 218 insertions(+), 106 deletions(-) diff --git a/include/efi.h b/include/efi.h index 6159f34ad2be..42f4e58a917e 100644 --- a/include/efi.h +++ b/include/efi.h @@ -37,12 +37,14 @@ #define EFIAPI __attribute__((ms_abi)) #define efi_va_list __builtin_ms_va_list #define efi_va_start __builtin_ms_va_start +#define efi_va_copy __builtin_ms_va_copy #define efi_va_arg __builtin_va_arg #define efi_va_end __builtin_ms_va_end #else #define EFIAPI asmlinkage #define efi_va_list va_list #define efi_va_start va_start +#define efi_va_copy va_copy #define efi_va_arg va_arg #define efi_va_end va_end #endif /* __x86_64__ */ diff --git a/include/efi_loader.h b/include/efi_loader.h index ad01395b39c3..2b294d64efd0 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -655,8 +655,10 @@ efi_status_t efi_remove_protocol(const efi_handle_t handle, /* Delete all protocols from a handle */ efi_status_t efi_remove_all_protocols(const efi_handle_t handle); /* Install multiple protocol interfaces */ -efi_status_t EFIAPI efi_install_multiple_protocol_interfaces - (efi_handle_t *handle, ...); +efi_status_t EFIAPI +efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...); +efi_status_t EFIAPI +efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...); /* Get handles that support a given protocol */ efi_status_t EFIAPI efi_locate_handle_buffer( enum efi_locate_search_type search_type, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 1bfd094e89f8..e776d25830f0 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2590,35 +2590,31 @@ found: } /** - * efi_install_multiple_protocol_interfaces() - Install multiple protocol + * efi_install_multiple_protocol_interfaces_int() - Install multiple protocol * interfaces * @handle: handle on which the protocol interfaces shall be installed - * @...: NULL terminated argument list with pairs of protocol GUIDS and - * interfaces + * @argptr: va_list of args * - * This function implements the MultipleProtocolInterfaces service. - * - * See the Unified Extensible Firmware Interface (UEFI) specification for - * details. + * Core functionality of efi_install_multiple_protocol_interfaces + * Must not be called directly * * Return: status code */ -efi_status_t EFIAPI efi_install_multiple_protocol_interfaces - (efi_handle_t *handle, ...) +static efi_status_t EFIAPI +efi_install_multiple_protocol_interfaces_int(efi_handle_t *handle, + efi_va_list argptr) { - EFI_ENTRY("%p", handle); - - efi_va_list argptr; const efi_guid_t *protocol; void *protocol_interface; efi_handle_t old_handle; - efi_status_t r = EFI_SUCCESS; + efi_status_t ret = EFI_SUCCESS; int i = 0; + efi_va_list argptr_copy; if (!handle) - return EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; - efi_va_start(argptr, handle); + efi_va_copy(argptr_copy, argptr); for (;;) { protocol = efi_va_arg(argptr, efi_guid_t*); if (!protocol) @@ -2628,104 +2624,212 @@ efi_status_t EFIAPI efi_install_multiple_protocol_interfaces if (!guidcmp(protocol, &efi_guid_device_path)) { struct efi_device_path *dp = protocol_interface; - r = EFI_CALL(efi_locate_device_path(protocol, &dp, - &old_handle)); - if (r == EFI_SUCCESS && + ret = EFI_CALL(efi_locate_device_path(protocol, &dp, + &old_handle)); + if (ret == EFI_SUCCESS && dp->type == DEVICE_PATH_TYPE_END) { EFI_PRINT("Path %pD already installed\n", protocol_interface); - r = EFI_ALREADY_STARTED; + ret = EFI_ALREADY_STARTED; break; } } - r = EFI_CALL(efi_install_protocol_interface( - handle, protocol, - EFI_NATIVE_INTERFACE, - protocol_interface)); - if (r != EFI_SUCCESS) + ret = EFI_CALL(efi_install_protocol_interface(handle, protocol, + EFI_NATIVE_INTERFACE, + protocol_interface)); + if (ret != EFI_SUCCESS) break; i++; } - efi_va_end(argptr); - if (r == EFI_SUCCESS) - return EFI_EXIT(r); + if (ret == EFI_SUCCESS) + goto out; /* If an error occurred undo all changes. */ - efi_va_start(argptr, handle); for (; i; --i) { - protocol = efi_va_arg(argptr, efi_guid_t*); - protocol_interface = efi_va_arg(argptr, void*); + protocol = efi_va_arg(argptr_copy, efi_guid_t*); + protocol_interface = efi_va_arg(argptr_copy, void*); EFI_CALL(efi_uninstall_protocol_interface(*handle, protocol, protocol_interface)); } - efi_va_end(argptr); - return EFI_EXIT(r); +out: + efi_va_end(argptr_copy); + return ret; + } /** - * efi_uninstall_multiple_protocol_interfaces() - uninstall multiple protocol - * interfaces - * @handle: handle from which the protocol interfaces shall be removed + * efi_install_multiple_protocol_interfaces() - Install multiple protocol + * interfaces + * @handle: handle on which the protocol interfaces shall be installed * @...: NULL terminated argument list with pairs of protocol GUIDS and * interfaces * - * This function implements the UninstallMultipleProtocolInterfaces service. + * + * This is the function for internal usage in U-Boot. For the API function + * implementing the InstallMultipleProtocol service see + * efi_install_multiple_protocol_interfaces_ext() + * + * Return: status code + */ +efi_status_t EFIAPI +efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...) +{ + efi_status_t ret; + efi_va_list argptr; + + efi_va_start(argptr, handle); + ret = efi_install_multiple_protocol_interfaces_int(handle, argptr); + efi_va_end(argptr); + return ret; +} + +/** + * efi_install_multiple_protocol_interfaces_ext() - Install multiple protocol + * interfaces + * @handle: handle on which the protocol interfaces shall be installed + * @...: NULL terminated argument list with pairs of protocol GUIDS and + * interfaces + * + * This function implements the MultipleProtocolInterfaces service. * * See the Unified Extensible Firmware Interface (UEFI) specification for * details. * * Return: status code */ -static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( - efi_handle_t handle, ...) +static efi_status_t EFIAPI +efi_install_multiple_protocol_interfaces_ext(efi_handle_t *handle, ...) { EFI_ENTRY("%p", handle); - + efi_status_t ret; efi_va_list argptr; + + efi_va_start(argptr, handle); + ret = efi_install_multiple_protocol_interfaces_int(handle, argptr); + efi_va_end(argptr); + return EFI_EXIT(ret); +} + +/** + * efi_uninstall_multiple_protocol_interfaces_int() - wrapper for uninstall + * multiple protocol + * interfaces + * @handle: handle from which the protocol interfaces shall be removed + * @argptr: va_list of args + * + * Core functionality of efi_uninstall_multiple_protocol_interfaces + * Must not be called directly + * + * Return: status code + */ +static efi_status_t EFIAPI +efi_uninstall_multiple_protocol_interfaces_int(efi_handle_t handle, + efi_va_list argptr) +{ const efi_guid_t *protocol; void *protocol_interface; - efi_status_t r = EFI_SUCCESS; + efi_status_t ret; size_t i = 0; + efi_va_list argptr_copy; if (!handle) - return EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; - efi_va_start(argptr, handle); + efi_va_copy(argptr_copy, argptr); for (;;) { protocol = efi_va_arg(argptr, efi_guid_t*); if (!protocol) break; protocol_interface = efi_va_arg(argptr, void*); - r = efi_uninstall_protocol(handle, protocol, - protocol_interface); - if (r != EFI_SUCCESS) + ret = efi_uninstall_protocol(handle, protocol, + protocol_interface); + if (ret != EFI_SUCCESS) break; i++; } - efi_va_end(argptr); - if (r == EFI_SUCCESS) { + if (ret == EFI_SUCCESS) { /* If the last protocol has been removed, delete the handle. */ if (list_empty(&handle->protocols)) { list_del(&handle->link); free(handle); } - return EFI_EXIT(r); + goto out; } /* If an error occurred undo all changes. */ - efi_va_start(argptr, handle); for (; i; --i) { - protocol = efi_va_arg(argptr, efi_guid_t*); - protocol_interface = efi_va_arg(argptr, void*); + protocol = efi_va_arg(argptr_copy, efi_guid_t*); + protocol_interface = efi_va_arg(argptr_copy, void*); EFI_CALL(efi_install_protocol_interface(&handle, protocol, EFI_NATIVE_INTERFACE, protocol_interface)); } + /* + * If any errors are generated while the protocol interfaces are being + * uninstalled, then the protocols uninstalled prior to the error will + * be reinstalled using InstallProtocolInterface() and the status code + * EFI_INVALID_PARAMETER is returned. + */ + ret = EFI_INVALID_PARAMETER; + +out: + efi_va_end(argptr_copy); + return ret; +} + +/** + * efi_uninstall_multiple_protocol_interfaces() - uninstall multiple protocol + * interfaces + * @handle: handle from which the protocol interfaces shall be removed + * @...: NULL terminated argument list with pairs of protocol GUIDS and + * interfaces + * + * This function implements the UninstallMultipleProtocolInterfaces service. + * + * This is the function for internal usage in U-Boot. For the API function + * implementing the UninstallMultipleProtocolInterfaces service see + * efi_uninstall_multiple_protocol_interfaces_ext() + * + * Return: status code + */ +efi_status_t EFIAPI +efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...) +{ + efi_status_t ret; + efi_va_list argptr; + + efi_va_start(argptr, handle); + ret = efi_uninstall_multiple_protocol_interfaces_int(handle, argptr); efi_va_end(argptr); + return ret; +} + +/** + * efi_uninstall_multiple_protocol_interfaces_ext() - uninstall multiple protocol + * interfaces + * @handle: handle from which the protocol interfaces shall be removed + * @...: NULL terminated argument list with pairs of protocol GUIDS and + * interfaces + * + * This function implements the UninstallMultipleProtocolInterfaces service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * Return: status code + */ +static efi_status_t EFIAPI +efi_uninstall_multiple_protocol_interfaces_ext(efi_handle_t handle, ...) +{ + EFI_ENTRY("%p", handle); + efi_status_t ret; + efi_va_list argptr; - /* In case of an error always return EFI_INVALID_PARAMETER */ - return EFI_EXIT(EFI_INVALID_PARAMETER); + efi_va_start(argptr, handle); + ret = efi_uninstall_multiple_protocol_interfaces_int(handle, argptr); + efi_va_end(argptr); + return EFI_EXIT(ret); } /** @@ -3785,9 +3889,9 @@ static struct efi_boot_services efi_boot_services = { .locate_handle_buffer = efi_locate_handle_buffer, .locate_protocol = efi_locate_protocol, .install_multiple_protocol_interfaces = - efi_install_multiple_protocol_interfaces, + efi_install_multiple_protocol_interfaces_ext, .uninstall_multiple_protocol_interfaces = - efi_uninstall_multiple_protocol_interfaces, + efi_uninstall_multiple_protocol_interfaces_ext, .calculate_crc32 = efi_calculate_crc32, .copy_mem = efi_copy_mem, .set_mem = efi_set_mem, diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index a6b98f066a0b..b6bd2d6af882 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -636,17 +636,18 @@ efi_status_t __weak efi_load_capsule_drivers(void) if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) { handle = NULL; - ret = EFI_CALL(efi_install_multiple_protocol_interfaces( - &handle, &efi_guid_firmware_management_protocol, - &efi_fmp_fit, NULL)); + ret = efi_install_multiple_protocol_interfaces(&handle, + &efi_guid_firmware_management_protocol, + &efi_fmp_fit, + NULL); } if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) { handle = NULL; - ret = EFI_CALL(efi_install_multiple_protocol_interfaces( - &handle, - &efi_guid_firmware_management_protocol, - &efi_fmp_raw, NULL)); + ret = efi_install_multiple_protocol_interfaces(&handle, + &efi_guid_firmware_management_protocol, + &efi_fmp_raw, + NULL); } return ret; diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index cf9fbd9cb54d..3354b217a9a4 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -1278,12 +1278,14 @@ efi_status_t efi_console_register(void) struct efi_device_path *dp; /* Install protocols on root node */ - r = EFI_CALL(efi_install_multiple_protocol_interfaces - (&efi_root, - &efi_guid_text_output_protocol, &efi_con_out, - &efi_guid_text_input_protocol, &efi_con_in, - &efi_guid_text_input_ex_protocol, &efi_con_in_ex, - NULL)); + r = efi_install_multiple_protocol_interfaces(&efi_root, + &efi_guid_text_output_protocol, + &efi_con_out, + &efi_guid_text_input_protocol, + &efi_con_in, + &efi_guid_text_input_ex_protocol, + &efi_con_in_ex, + NULL); /* Create console node and install device path protocols */ if (CONFIG_IS_ENABLED(DM_SERIAL)) { diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 39ea1a68a683..fb96b0508528 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -449,10 +449,12 @@ static efi_status_t efi_disk_add_dev( * in this case. */ handle = &diskobj->header; - ret = EFI_CALL(efi_install_multiple_protocol_interfaces( - &handle, &efi_guid_device_path, diskobj->dp, - &efi_block_io_guid, &diskobj->ops, - guid, NULL, NULL)); + ret = efi_install_multiple_protocol_interfaces(&handle, + &efi_guid_device_path, + diskobj->dp, + &efi_block_io_guid, + &diskobj->ops, guid, + NULL, NULL); if (ret != EFI_SUCCESS) goto error; diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 3d6044f76047..87fde3f88c2b 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -208,14 +208,13 @@ efi_status_t efi_initrd_register(void) if (ret != EFI_SUCCESS) return ret; - ret = EFI_CALL(efi_install_multiple_protocol_interfaces - (&efi_initrd_handle, - /* initramfs */ - &efi_guid_device_path, &dp_lf2_handle, - /* LOAD_FILE2 */ - &efi_guid_load_file2_protocol, - (void *)&efi_lf2_protocol, - NULL)); + ret = efi_install_multiple_protocol_interfaces(&efi_initrd_handle, + /* initramfs */ + &efi_guid_device_path, &dp_lf2_handle, + /* LOAD_FILE2 */ + &efi_guid_load_file2_protocol, + (void *)&efi_lf2_protocol, + NULL); return ret; } diff --git a/lib/efi_loader/efi_root_node.c b/lib/efi_loader/efi_root_node.c index 739c6867f412..a4eb6f493dc2 100644 --- a/lib/efi_loader/efi_root_node.c +++ b/lib/efi_loader/efi_root_node.c @@ -49,38 +49,38 @@ efi_status_t efi_root_node_register(void) dp->end.length = sizeof(struct efi_device_path); /* Create root node and install protocols */ - ret = EFI_CALL(efi_install_multiple_protocol_interfaces - (&efi_root, - /* Device path protocol */ - &efi_guid_device_path, dp, + ret = efi_install_multiple_protocol_interfaces + (&efi_root, + /* Device path protocol */ + &efi_guid_device_path, dp, #if CONFIG_IS_ENABLED(EFI_DEVICE_PATH_TO_TEXT) - /* Device path to text protocol */ - &efi_guid_device_path_to_text_protocol, - (void *)&efi_device_path_to_text, + /* Device path to text protocol */ + &efi_guid_device_path_to_text_protocol, + &efi_device_path_to_text, #endif -#ifdef CONFIG_EFI_DEVICE_PATH_UTIL - /* Device path utilities protocol */ - &efi_guid_device_path_utilities_protocol, - (void *)&efi_device_path_utilities, +#if CONFIG_IS_ENABLED(EFI_DEVICE_PATH_UTIL) + /* Device path utilities protocol */ + &efi_guid_device_path_utilities_protocol, + &efi_device_path_utilities, #endif -#ifdef CONFIG_EFI_DT_FIXUP - /* Device-tree fix-up protocol */ - &efi_guid_dt_fixup_protocol, - (void *)&efi_dt_fixup_prot, +#if CONFIG_IS_ENABLED(EFI_DT_FIXUP) + /* Device-tree fix-up protocol */ + &efi_guid_dt_fixup_protocol, + &efi_dt_fixup_prot, #endif #if CONFIG_IS_ENABLED(EFI_UNICODE_COLLATION_PROTOCOL2) - &efi_guid_unicode_collation_protocol2, - (void *)&efi_unicode_collation_protocol2, + &efi_guid_unicode_collation_protocol2, + &efi_unicode_collation_protocol2, #endif #if CONFIG_IS_ENABLED(EFI_LOADER_HII) - /* 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 string protocol */ + &efi_guid_hii_string_protocol, + &efi_hii_string, + /* HII database protocol */ + &efi_guid_hii_database_protocol, + &efi_hii_database, #endif - NULL)); + NULL); efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE; return ret; } From patchwork Thu Oct 6 19:40:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 612925 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp435570pvb; Thu, 6 Oct 2022 12:41:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM450usonXWYNWwQEdtd+tKNIzzERNI1XRKiGdTnsc7fcLl43IgLG8cyXVtAEJwcaWiyYhVZ X-Received: by 2002:a05:6402:3549:b0:454:414e:a7fd with SMTP id f9-20020a056402354900b00454414ea7fdmr1361386edd.69.1665085265122; Thu, 06 Oct 2022 12:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665085265; cv=none; d=google.com; s=arc-20160816; b=B+yCItdyS4JCooiHnOJ0laG72sfVQNNtBrKy7IaX2GsCKmT6QaPkYb+K/ZYxSzHT7e 0KFhn79Q7V/GV0tBk84woQDkj+n0ur4mMQOo+2Wy0E9hGpAajlwhckB9Rp71BVbeolSa z9/KzwAQ8gd+4dgp+m9nFl4OS1BvvJEoCfxy/Y+sN/8VbsxSKYdNhJQekbtzDIg881HY xl1sj4M3r31R6akEXYGfx24zCK4Utmy7P3TMJw2rL1jzXeJ6s8c3e0yysLvOKFf5CB3C Jw15rDutxb3AL6P+6Xl3yIsWQ90q+q6uO1xIdrl8M97FOtjcKLup2Apu3Qq9iQKZWs3f yAbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zKgX0GuSOleR6TMszLnkxlsjzjpW8+nOg4U1SQF/60Q=; b=mvhChoBtZ4kDkYVM7JnKvfLAMyXUyRaJ+GagZbMHhcaWRXo6LQGF7tZj5BFvxW15W3 7a3KZkiTHbycKZ/H5ksfMGH5+0Kp14AR1V6j2jS/o7VXVwUniI0u/7L4ZRelXX/NGdHR Fskex4qmD5NjQbe03zJMQ5k5njfLgion1O5WXzdmbDGM+jpu1EXHfgW2L7yeRsW9Lhcr ReUntahMmHa8gEtAolQNYTXupxreNH7bqd3G0/YRujEHhCB79JyI0O3fvgMHG8og4OzN uyy4JZxt2U7gGdmghfyrgiOW6sYZq4zxCb4L7xB4/dz3qtUTJB1TtcVk9GXSb/f54O9o ikQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zDEzi/HC"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id i10-20020a05640242ca00b0044f288e02edsi204020edc.15.2022.10.06.12.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 12:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zDEzi/HC"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A00BB84E09; Thu, 6 Oct 2022 21:40:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="zDEzi/HC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6366784DAA; Thu, 6 Oct 2022 21:40:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BD13184D99 for ; Thu, 6 Oct 2022 21:40:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x530.google.com with SMTP id m15so4242583edb.13 for ; Thu, 06 Oct 2022 12:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=zKgX0GuSOleR6TMszLnkxlsjzjpW8+nOg4U1SQF/60Q=; b=zDEzi/HCHYay5FaLyiUw81khmOJYurxCLkQ4IKZZmP1EHPbqQrQpHPDfbZ8kaDVBWx MiM5MUlx5pSZ0uqgUHf4jaTsKSn6yQ7w992v0jrx31xM81xSX2p0SCOnczGRf84l5cbt RMyqWXTIMgEZ3oQGkLXZHtxD/LQnmJNf9uyxug3l0CAXL3O84/NcjL2d4uU1tQ474KTE KmmzTmtXZsmJ/ukKcp1dGNpWZQaBbiH6g8Ni9aa/VzoLrL6EBCmyMw4B3RpIfYtEXAPy 9jJ6nPCcOeJnQ1cUGHfDtz3t3RI1ym4n+noeRCPkD08gjJBVKVrCDB29WPHIwhE1UbGy q0sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=zKgX0GuSOleR6TMszLnkxlsjzjpW8+nOg4U1SQF/60Q=; b=XtSpRL4MCNYa/wSBIMV+zbQplz8ZaDB/humxRUgtq35uu0Dw6ENx3O4rd5x8gK+TCw VRLYRZqzXHMKGLasZAfnvw6mdLHUrCmJu3GEYt/GSPZiwxk2NJrlabBI+UFMWrKJsukc VwG5dhv5tzz4SgTp6U3pkTvELVcJoonlemnIlLgohLf0Wx51gt58RTWRd9CUfJzhctBl /ELAPlhgt/xS08y2mHNQ/SMR+9bga0azoXKL9Oq3/Fa5kH/McyTCyWOloK3QOYzQ4sZF 905kFwelv4ItaqKoboVuoph9Zx72rmCOzh6YXchFbdkIxCNiZaZEFhojd5p848aTwAOy ITIg== X-Gm-Message-State: ACrzQf3B8IY3yXYq23zyL49K3ReqQkou83F+VM83yg/0VS2SzQZ490tV lw6zYcj/1JedCJ517GDXv7F4rg== X-Received: by 2002:a50:bb68:0:b0:458:ab56:a8c0 with SMTP id y95-20020a50bb68000000b00458ab56a8c0mr1334065ede.103.1665085238332; Thu, 06 Oct 2022 12:40:38 -0700 (PDT) Received: from hades.. (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id bo1-20020a170906d04100b0077b2b0563f4sm99147ejb.173.2022.10.06.12.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 12:40:37 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , u-boot@lists.denx.de Subject: [PATCH 2/2 v2] cmd: replace efi_create_handle/add_protocol with InstallMultipleProtocol Date: Thu, 6 Oct 2022 22:40:24 +0300 Message-Id: <20221006194028.28358-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221006194028.28358-1-ilias.apalodimas@linaro.org> References: <20221006194028.28358-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean In general handles should only be deleted if the last remaining protocol is removed. Instead of explicitly calling efi_create_handle -> efi_add_protocol -> efi_delete_handle which blindly removes all protocols from a handle before removing it, use InstallMultiple/UninstallMultiple which adheres to the EFI spec and only deletes a handle if there are no additional protocols present Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 3041873afbbc..b93c0d3d4c02 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -492,7 +492,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) efi_handle_t mem_handle = NULL, handle; struct efi_device_path *file_path = NULL; struct efi_device_path *msg_path; - efi_status_t ret; + efi_status_t ret, ret2; u16 *load_options; if (!bootefi_device_path || !bootefi_image_path) { @@ -509,12 +509,9 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) * Make sure that device for device_path exist * in load_image(). Otherwise, shell and grub will fail. */ - ret = efi_create_handle(&mem_handle); - if (ret != EFI_SUCCESS) - goto out; - - ret = efi_add_protocol(mem_handle, &efi_guid_device_path, - file_path); + ret = efi_install_multiple_protocol_interfaces(&mem_handle, + &efi_guid_device_path, + file_path, NULL); if (ret != EFI_SUCCESS) goto out; msg_path = file_path; @@ -542,9 +539,11 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) ret = do_bootefi_exec(handle, load_options); out: - efi_delete_handle(mem_handle); + ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle, + &efi_guid_device_path, + file_path, NULL); efi_free_pool(file_path); - return ret; + return (ret != EFI_SUCCESS) ? ret : ret2; } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST