From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2F7BC433FE for ; Thu, 6 Oct 2022 07:38:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2F5E484BAA; Thu, 6 Oct 2022 09:38:51 +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="VcdMFEf8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7FDF384A35; Thu, 6 Oct 2022 09:38:49 +0200 (CEST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (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 0BF2083914 for ; Thu, 6 Oct 2022 09:38:47 +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-ej1-x62b.google.com with SMTP id z23so2576738ejw.12 for ; Thu, 06 Oct 2022 00:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=HqgLolOytpnUgSzunkgGvmsaPxmKoOVdt3B6EcErN5I=; b=VcdMFEf8icFJfJ6qjl7e6epZ5YE3uKoqeUkBTgddmP+HiQRSgyD68wpF55ibmt+2kQ NV+9L4naAvjjXwe7PWKSGsYE6CXcYHZNLS4363fXcS+U480FNX4Y8VCu4YBclocGN8DC RXzPCP+jVAA0CzqPj+Iz9gNmJS8jIHltNy01Q0s+9deNysi9ANVahYm6s5Tf1O+pAb3s Oq2hBrEGSty5elAb6qxNlnMLIdzCf/Dl/dp7w46SFu6M93KqofHdH7cdxK+nVOP7BD+I hewv6pT2FV1I4GpZs79Uh7suKPbdliFhUeA415z7takVuVCXqOsG5gc0r+EO0PDXmwDe O1jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=HqgLolOytpnUgSzunkgGvmsaPxmKoOVdt3B6EcErN5I=; b=CO6IQEj9eU/LVe3x6m4nTDVDxsNA3kGgM06pHBwblseY8qpxAkxVvWamA9OqldBX1e ja0BuXDLWnx5IKXQcYVSnGjgbQbznmHHrEKOTmajdc/gIxj9U4zzhIsc5k90H5Q3jo62 VNjvMcE2M7y4TRAFxRGvl6RSmKbuIKzREl6hcUB1Qxutsevyo0uXHdMqwidUA7Tsbuqg lbCwCPls2EEBfEr/PNqTp9Yop8XIuQzl+La+Gu3z8nv0lq1csWZYHLdoW7fudu3HYQV5 u3ercsIWcZ57FgTmB54yvBCyRGxAdbA4MGFPTxzYP0TiG3biwn3e52TmAxsV0YCMjKmW 4Q+A== X-Gm-Message-State: ACrzQf35hboaJv9lnH8o8Nq/3EhS+R1AefDBz29VPU1utGWTCvvhjE0Y jFvhKIlcWY+9kPu9R2UlWyMoYg== X-Google-Smtp-Source: AMsMyM6YhGT8QZrf302D161hseaQFO9/+Q5YrjCV9AYgnPRzplYCuOxN7glFbVGSiQLlA7c9pUqmRQ== X-Received: by 2002:a17:906:fd82:b0:770:7e61:3707 with SMTP id xa2-20020a170906fd8200b007707e613707mr2843930ejb.143.1665041926679; Thu, 06 Oct 2022 00:38:46 -0700 (PDT) Received: from hera (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id n9-20020a509349000000b004580862ffdbsm5273194eda.59.2022.10.06.00.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 00:38:46 -0700 (PDT) Date: Thu, 6 Oct 2022 10:38:44 +0300 From: Ilias Apalodimas To: Heinrich Schuchardt Cc: AKASHI Takahiro , u-boot@lists.denx.de Subject: Re: [RFC PATCH 2/2] cmd: replace efi_create_handle/add_protocol with InstallMultipleProtocol Message-ID: References: <20221005152603.3085754-1-ilias.apalodimas@linaro.org> <20221005152603.3085754-3-ilias.apalodimas@linaro.org> <20221006015346.GC38245@laputa> <62e539e4-6c51-b457-5c64-37f71770d3aa@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <62e539e4-6c51-b457-5c64-37f71770d3aa@gmx.de> 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 On Thu, Oct 06, 2022 at 04:26:37AM +0200, Heinrich Schuchardt wrote: > On 10/6/22 03:53, AKASHI Takahiro wrote: > > On Wed, Oct 05, 2022 at 06:26:02PM +0300, Ilias Apalodimas wrote: > > > 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); > > > > nitpick: NULL -> NULL, NULL > > UEFI spec seems to require "A variable argument list containing pairs of > > protocol GUIDs and protocol interfaces" even if a protocol interface won't be > > used with GUID as NULL. > > The spec also has: > "The pairs of arguments are removed in order from the variable argument > list until a NULL protocol GUID value is found." > > This is what a calls inside EDK II looks like: > > Status = CoreInstallMultipleProtocolInterfaces ( > &mDecompressHandle, > &gEfiDecompressProtocolGuid, > &gEfiDecompress, > NULL > ); > > gBS->UninstallMultipleProtocolInterfaces ( > Controller, > &gEfiCallerIdGuid, > AtaBusDriverData, > NULL > ); > > So I am happy with a single NULL here. > > > > > -Takahiro Akashi > > > > > 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); > > We have installed a lot more protocols. The binary may have installed > additional protocols. Consider the case of a boottime driver. To delete > the handle we would have to remove all installed protocols. > > UninstallMultipleProtocolInterfaces() may fail if one of the protocols > was opened with ByDriver or ByChildcontroller. The return value has to > be considered before freeing file_path. Ok I'll fix it in v2 > > Best regards > > Heinrich > > > > efi_free_pool(file_path); > > > return ret; > > > } > > > -- > > > 2.34.1 > > > > Thanks /Ilias