From patchwork Wed Oct 5 15:26:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 612535 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp891580pvb; Wed, 5 Oct 2022 08:26:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6TllmWzp69qZftb+YrHtreWZ9fzt4kvzAWGiDyqJBQ/TB+41cNSjV9nGHLEHuNPzbF5Taa X-Received: by 2002:a05:6402:d0b:b0:458:a244:4e99 with SMTP id eb11-20020a0564020d0b00b00458a2444e99mr323889edb.46.1664983604569; Wed, 05 Oct 2022 08:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664983604; cv=none; d=google.com; s=arc-20160816; b=lefT+1s/sZoLNWRoxgsnZHa7aUiC+63q4X2BjjeonUAvVVw01/a9B7iXr21ieQE4jr iAkkrRMpUp4/QzzfiVSOsmz8nlCzFV2dBsFD5tHST0hKVlqnEOvcCTOfSu5Cjs7ZdRB5 3MYsUDO8YW8d2kDU0CpVt5IN96zyd7MFIy6D6XSn4KlJlyXKh+n0ERiqBl5Mf+izy7PS A0aQOj3xcC1/i5aoS4LdV/FVbQLiPAhFjnsqJHq96VP+QSs/4C6tO6pGWtC6CH21IsW5 tyjOSe5NB7ZSbTBfm+zq1pPi5tduYuKiVIXEDBLJSQOtgQpl/T/kV2iuccwfc/tNNFC2 TnOA== 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=cLqCr4H1FV8Te1sCbria80j8yPKPqOkyx6GDbagyiLs=; b=trhmKxqMmTXq00TPnEP2sTdurzPYyX6FUUDvpN122V9Iz8Gs3ZXNn0HY0+Eh1sC29X hHz38KHA02EEwjDlAsLcXRNxmXFVU+YmL97zQ5obHfG8jnP7dIFjm2w53mbVg8ZpoAb/ TkRyJ/ZkqSw+okR1EDsbEtt6L1c1fObFYRIAMP60L6nAdCzcnckSDJYsQLB3AiGKF8Yz ygKfUs421bGJcF7ULAdNFBbQBSJxMHTfLkR48YtEvurnNPGwUPSaBEqPA9pE99lRBO7v y3CBy5qlm1l0XrN5Zw3v3o2ebal/P+Ck2gxUAryKQJ/nLZAHzOsc9GmB79PA5DdIBJ7y U3EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="qoRRB4W/"; 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 he41-20020a1709073da900b00782d3ab55e5si16180477ejc.737.2022.10.05.08.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:26:44 -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="qoRRB4W/"; 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 3F7FF84D8C; Wed, 5 Oct 2022 17:26:33 +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="qoRRB4W/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9846C84D82; Wed, 5 Oct 2022 17:26:31 +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-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) (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 18F8784D8C for ; Wed, 5 Oct 2022 17:26:27 +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-x52a.google.com with SMTP id e18so23470763edj.3 for ; Wed, 05 Oct 2022 08:26:27 -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=cLqCr4H1FV8Te1sCbria80j8yPKPqOkyx6GDbagyiLs=; b=qoRRB4W/kzA94lKnSDTZZyar7xePVDF4IDMdZVcOLD/D6zb3vIWpbBiNzZNsiOZmzl SovD5nciloGsOE6VFEiVHUmDMtoPCL1NWCgRAQP8DRVv/Ri5YHsx1xYZpHvP7AJq1/ku obSzop+9NGlbjqMquc266Db40OEOueyFmnPbzhkUuiJRskBlkqJjK9atvqGonp8/H/as EJPJoBcTNM0BnLBeog8/vyYtDD/4SPfSp4NJmqi8h0FUPJx5kkq7vpxes31lBxz/1f3L nSAsA6K+QC0yL30CuHqUxD7eKX9WZUki37n0OHylGmxFvck3NRhKs8ritdvS0obAWnBn nIsg== 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=cLqCr4H1FV8Te1sCbria80j8yPKPqOkyx6GDbagyiLs=; b=pUugLkNfD5hqEnomY0/UXviVsbeq86KMu+YIkaPBmFKlHgH5hO6rVlwhoMOwyVqHd/ D0VFFssm4ftJPGsbzc6USbaxq58MLPZ2UMThCbpEp5O2IhqxpIPd6hekMzWScLNV7cXY THbkrXT+P2YaT/mv+ciN23tHZSgCzq7KkI8muR2zdvOrg1iJ0pcwfUo2Cjp5VmLBorR8 lMbnzsWgEd5UzUdj/XJfzl052CRQXuVt6Y9+Jh9Q23BDSSfIopHMH3CVRexwRp0tOnhK lMS67wYo950CoyUoKeREisc+qSbOrsZN2XVm5psKoTPQ0UZkMQFsU0OWXe5+2syPmkJv /4sw== X-Gm-Message-State: ACrzQf09qNjv6b6MZOI76Po2Bm1QjWtKNsbAE4FdnpeujZnFXMaxhGmL L9P9SRCBoOwaWewyLOcUZJYAjUBl/PIIyg== X-Received: by 2002:a05:6402:2074:b0:458:ad26:d5c2 with SMTP id bd20-20020a056402207400b00458ad26d5c2mr313695edb.332.1664983586611; Wed, 05 Oct 2022 08:26:26 -0700 (PDT) Received: from hades.. (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id n15-20020aa7c78f000000b00458d50b4a24sm3918815eds.96.2022.10.05.08.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:26:26 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , u-boot@lists.denx.de Subject: [RFC PATCH 1/2] efi_loader: define internal implementations of install/uninstallmultiple Date: Wed, 5 Oct 2022 18:26:01 +0300 Message-Id: <20221005152603.3085754-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005152603.3085754-1-ilias.apalodimas@linaro.org> References: <20221005152603.3085754-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. 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 --- include/efi.h | 2 + include/efi_loader.h | 6 +- lib/efi_loader/efi_boottime.c | 180 ++++++++++++++++++++++++------- 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 | 44 ++++---- 8 files changed, 197 insertions(+), 89 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..aeb8b27dc676 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() - 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. + * @argptr: va_list of args * - * 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(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; 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) @@ -2646,52 +2642,103 @@ efi_status_t EFIAPI efi_install_multiple_protocol_interfaces break; i++; } - efi_va_end(argptr); - if (r == EFI_SUCCESS) - return EFI_EXIT(r); + if (r == EFI_SUCCESS) { + efi_va_end(argptr_copy); + return r; + } /* 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); + efi_va_end(argptr_copy); + + return r; - return EFI_EXIT(r); } /** - * 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 r = EFI_SUCCESS; + efi_va_list argptr; + + efi_va_start(argptr, handle); + r = __efi_install_multiple_protocol_interfaces(handle, argptr); + efi_va_end(argptr); + return r; +} + +/** + * 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 r = EFI_SUCCESS; efi_va_list argptr; + + efi_va_start(argptr, handle); + r = __efi_install_multiple_protocol_interfaces(handle, argptr); + efi_va_end(argptr); + return EFI_EXIT(r); +} + +/** + * __efi_uninstall_multiple_protocol_interfaces() - 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(efi_handle_t handle, + efi_va_list argptr) +{ const efi_guid_t *protocol; void *protocol_interface; efi_status_t r = EFI_SUCCESS; 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) @@ -2703,29 +2750,82 @@ static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( break; i++; } - efi_va_end(argptr); if (r == 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); + efi_va_end(argptr_copy); + return r; } /* 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)); } - efi_va_end(argptr); + efi_va_end(argptr_copy); /* In case of an error always return EFI_INVALID_PARAMETER */ - return EFI_EXIT(EFI_INVALID_PARAMETER); + return EFI_INVALID_PARAMETER; +} + +/** + * 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 r = EFI_SUCCESS; + efi_va_list argptr; + + efi_va_start(argptr, handle); + r = __efi_uninstall_multiple_protocol_interfaces(handle, argptr); + efi_va_end(argptr); + return r; +} + +/** + * 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 r = EFI_SUCCESS; + efi_va_list argptr; + + efi_va_start(argptr, handle); + r = __efi_uninstall_multiple_protocol_interfaces(handle, argptr); + efi_va_end(argptr); + return EFI_EXIT(r); } /** @@ -3785,9 +3885,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..b4696d54c33d 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, + (void *)&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, + /* Device path utilities protocol */ + &efi_guid_device_path_utilities_protocol, + (void *)&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, + /* Device-tree fix-up protocol */ + &efi_guid_dt_fixup_protocol, + (void *)&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, + (void *)&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, + (void *)&efi_hii_string, + /* HII database protocol */ + &efi_guid_hii_database_protocol, + (void *)&efi_hii_database, #endif - NULL)); + NULL); efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE; return ret; } From patchwork Wed Oct 5 15:26:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 612536 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp891690pvb; Wed, 5 Oct 2022 08:26:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5LJiYZPRJYEAuVP/EayIsRL/YBLoBWcF/pCNjX9MEAgEN0zbn0usNZh35GSsVLloo4Jkmv X-Received: by 2002:a50:9510:0:b0:453:dded:60e with SMTP id u16-20020a509510000000b00453dded060emr311695eda.204.1664983615168; Wed, 05 Oct 2022 08:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664983615; cv=none; d=google.com; s=arc-20160816; b=q6icZnH+rutsUOsbpLPjpd+yQSmg/ABHuFVOC1DIkLarqmxGQ0mZRSAk4kFvfHFf6I PMot5zaklehf3BueATm8YhHyAvjVu892CcdtO+ML22I8u7mtXAS41ze6XqKtlahFcNvC tD/P3g31LL1sfi98qaEYlBtIOJk6OO5RvM2i0ajnumzpZQs/2fhL6gtLAXfpJuedayrw zMKg5sSMmkkvOe3QpGaf1GznzZL9Yvi6eNyxqNHSe61rCoST9xATlVyIC8FvrPveK1sa MTxVrUeMjVX2ONpXMhaVHLuGpy+AiVl60Jws9/HaGgb7dJeN8FQF2HH7v0rdb9zPS7JX Ix+A== 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=6MrOgdaTi6CwJiEdBgg5+2Zmcf+m2ZcJoVQWPPkt+hk=; b=WhUQJqknIuiWkrfWbKdrWI8tClqM/pVZygxz+f14yS41/KV6140LbdJjkM3CfZt0SQ 56xEs/CoLLNCBpAvU8fy78S5VbkOxjtEFW+9BW/MnuLDzEoeMg0FqgrFJizac33VjpMA 5dYMVJ5qk7ResXNOu20k+GsaM+z8A358yxiPiKw3shaPBDFWOmUR6nsQk/AiL4vdfi8X B/Mpzc5Pk67dk4+bYvJMoP4YSsHzs7hiQC0PiLvws3idEzAeDykmAwrGXBy6uPSeMPTB qWTZ7fDHKfO5W5IkMrntvnxNqwvd78sLNeOXZocDzzefUQouNZvXeCWTgeG47WZ6iwIn ni+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x7b8EYvj; 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 hc19-20020a170907169300b00774195db4e7si15208628ejc.117.2022.10.05.08.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:26:55 -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=x7b8EYvj; 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 3527B84E3B; Wed, 5 Oct 2022 17:26: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=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="x7b8EYvj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 37B7984E0F; Wed, 5 Oct 2022 17:26:34 +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-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (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 8863284D96 for ; Wed, 5 Oct 2022 17:26:29 +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-x52e.google.com with SMTP id y8so23478738edc.10 for ; Wed, 05 Oct 2022 08:26:29 -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=6MrOgdaTi6CwJiEdBgg5+2Zmcf+m2ZcJoVQWPPkt+hk=; b=x7b8EYvjbrloLivuQYEroYWGoK8ybWQiKrv/vgjvpAkvl0NAz10g1mLO6Icjk1jmRT UG+wSGT6UUc9g+JvcqpRAd8S5aa2U1SjaEKmpRadl3WEbfoLvJHozgXi0GEBmG8SLbn5 LmFCbtSxtsStOyT1BgBjD8Hu+1LupPnbyA/J3jGKi6296+wI9eRvmGklQTiQ/VK7S+YD M7lZ4/r8WZZ9BvPrgIZTT3roybpao3YsUsg+P6UzRqHngJgjlu7+OhNx7EYCOYb3XLha 5bW7i8WKznxRxOGCD0hZcqdakDy3c5fcZcyXbKZJBJXMquSSnqBSYlFrZE8hAhyRKiq5 x/dQ== 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=6MrOgdaTi6CwJiEdBgg5+2Zmcf+m2ZcJoVQWPPkt+hk=; b=d+wy2YUUM1PNHpEiQeFdfEr2mfBSbhUV58xKWp2aDq18+aiW6ceGO/dIURnnZFZVZq zCw35LUTOGZ63O6VlkWj4bHQs3/kCXGs/Je8B2HRhyiZHjTE4K5xS+5eMQqVfllPiuvR 8oOi1N7XASIV4f9Zby09zLGISWxCI/trKLbtqcKEwcNNh3BRDx8ajHcbUd4uSYrVlisR mElfkeYbbed4LH/yeOZvTNijli0fAIVUeQoAgisqycKgPFU1N4jr+QXBDe0aDw6imqpt tXCqFBpSmdsJgGjLoJfXbtm9rfhsvR3nDht0/FWfWP08YoTrsEBHdOzD/Ds6ILUFz8dt 4RtA== X-Gm-Message-State: ACrzQf37c78yjdwsqAUpsiKjcSHtqkNTKBP12XTIgT6ZVLB5G6c+HfM6 6MtHuF9TvE/V/3XyMPRv6+0l/A== X-Received: by 2002:a05:6402:448b:b0:43b:5ec6:8863 with SMTP id er11-20020a056402448b00b0043b5ec68863mr260201edb.377.1664983589073; Wed, 05 Oct 2022 08:26:29 -0700 (PDT) Received: from hades.. (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id n15-20020aa7c78f000000b00458d50b4a24sm3918815eds.96.2022.10.05.08.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 08:26:28 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , u-boot@lists.denx.de Subject: [RFC PATCH 2/2] cmd: replace efi_create_handle/add_protocol with InstallMultipleProtocol Date: Wed, 5 Oct 2022 18:26:02 +0300 Message-Id: <20221005152603.3085754-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005152603.3085754-1-ilias.apalodimas@linaro.org> References: <20221005152603.3085754-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 --- cmd/bootefi.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 3041873afbbc..4ab68868cc7e 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -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,7 +539,9 @@ 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); + efi_uninstall_multiple_protocol_interfaces(mem_handle, + &efi_guid_device_path, + file_path, NULL); efi_free_pool(file_path); return ret; }