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 X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D5F5C433F5 for ; Thu, 9 Sep 2021 06:01:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AC2C460F43 for ; Thu, 9 Sep 2021 06:01:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AC2C460F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A7C382C2B; Thu, 9 Sep 2021 08:01:41 +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="CN0KKH8z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0C68D80C94; Thu, 9 Sep 2021 08:01:40 +0200 (CEST) Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 A807280C94 for ; Thu, 9 Sep 2021 08:01:36 +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=takahiro.akashi@linaro.org Received: by mail-pj1-x1029.google.com with SMTP id k23-20020a17090a591700b001976d2db364so647582pji.2 for ; Wed, 08 Sep 2021 23:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=I89Nn6kJkixGYlZn3Qq2eQOOjbCO3MoKuHea3C30JJM=; b=CN0KKH8zQtlwv9mrJdiHvOrz7B/0pSP+wRrrVhSF8tXMXpFHOH9W6K+PIpeOD5X4cC F/GyDuUqeOlrijfDKEDA0bwJEEGQGM+lqc2ZgNH51RNsqkDSxtgXbT1r+byTwgewBF5z hr2dhqlhQKjrA+V5UxnPgPIll55NpRCpn7DUCALH6nBOIvH4KwNq5K2ibEOqRtUfVfGk 2mFKhAlCA2MkJWSJZcB6bd7xm4vYEGU1LKUJ0PoCGgy2+lrXHDvBKKOFviDHvjdOF2l5 fAdB6EKzHh4F7n2esvZxQg1uDRyPqFPnM2FRjG/sN+rkHi7iw6COpD6Sh7TBgMiZsCfP ZHUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=I89Nn6kJkixGYlZn3Qq2eQOOjbCO3MoKuHea3C30JJM=; b=VYEgfhxToHQchW07Y6Q9931lG1S+5uR4j57wpR95qc8JyLV6qmNYZzrkiGwNCdJ+cw jD5xVNwMkoVARSuf9vFYvexR7UzoAnc749NaEwbMiFwrILlnyMw+LwTyvgHf2yjeMUB7 /07CSoVzlxtNL+oXX+Xo9vhbT79bmW139d6npEMIChrCjy8AMPcSfNJH80zV7ole/5Nl G4ieGJnvp1pdAp7XjPVG0Oe9iTshzQUeQsCofc/580J6oV+UjNUlw4i0BAlXOF5XeWNw NrJNPwYfwmQZasBIew3G8fYNK3mO9pEaYi3mC4MlI7OE2aLUol8ckcAkneQ4dFAO2b62 3SLg== X-Gm-Message-State: AOAM531MmVNuWjRRAW5k/cP3IsNlmqobgWYYOib086lJMdSBGcW0oggg w6BLt5RZnbSmNrWQh+RmffoY9g== X-Google-Smtp-Source: ABdhPJyx8wVJ7yl6wyX0LT6prs0aQYdL2VVjvPtTcUgDEZRZgoJYPpfCQf7eejkAl5ViTqc05wzZkw== X-Received: by 2002:a17:902:7c08:b0:13a:4062:592c with SMTP id x8-20020a1709027c0800b0013a4062592cmr1416872pll.58.1631167294764; Wed, 08 Sep 2021 23:01:34 -0700 (PDT) Received: from laputa (p784a2304.tkyea130.ap.so-net.ne.jp. [120.74.35.4]) by smtp.gmail.com with ESMTPSA id o6sm813081pjk.4.2021.09.08.23.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 23:01:34 -0700 (PDT) Date: Thu, 9 Sep 2021 15:01:30 +0900 From: AKASHI Takahiro To: Ilias Apalodimas Cc: xypron.glpk@gmx.de, masahisa.kojima@linaro.org, Alexander Graf , u-boot@lists.denx.de Subject: Re: [PATCH] efi_loader: Remove incorrect calls of EFI_CALL in TCG2 Message-ID: <20210909060130.GB56666@laputa> Mail-Followup-To: AKASHI Takahiro , Ilias Apalodimas , xypron.glpk@gmx.de, masahisa.kojima@linaro.org, Alexander Graf , u-boot@lists.denx.de References: <20210908213049.89268-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210908213049.89268-1-ilias.apalodimas@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Heinrich, On Thu, Sep 09, 2021 at 12:30:49AM +0300, Ilias Apalodimas wrote: > There is two unneeded EFI_CALL references in tcg2_measure_pe_image(). > The first one in efi_search_protocol() and the second on in the device path > calculation. The second isn't even a function we should be calling, but a > pointer assignment, which happens to work with the existing macro. It is a quite common mistake. For most people, it is not very trivial when we should use EFI_CALL and when should not. Do you think that we should leave a note somewhere? It would be much better if we can check any occurrence of mismatch, say using EFI_CALL for a non-EFIAPI function, at compile time. -Takahiro Akashi > While at it switch the malloc call to a calloc, remove the unnecessary cast > and get rid of an unneeded if statement before copying the device path > > Signed-off-by: Ilias Apalodimas > --- > lib/efi_loader/efi_tcg2.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c > index 1319a8b37868..d026af2b2350 100644 > --- a/lib/efi_loader/efi_tcg2.c > +++ b/lib/efi_loader/efi_tcg2.c > @@ -839,20 +839,19 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, > if (ret != EFI_SUCCESS) > return ret; > > - ret = EFI_CALL(efi_search_protocol(&handle->header, > - &efi_guid_loaded_image_device_path, > - &handler)); > + ret = efi_search_protocol(&handle->header, > + &efi_guid_loaded_image_device_path, &handler); > if (ret != EFI_SUCCESS) > return ret; > > - device_path = EFI_CALL(handler->protocol_interface); > + device_path = handler->protocol_interface; > device_path_length = efi_dp_size(device_path); > if (device_path_length > 0) { > /* add end node size */ > device_path_length += sizeof(struct efi_device_path); > } > event_size = sizeof(struct uefi_image_load_event) + device_path_length; > - image_load_event = (struct uefi_image_load_event *)malloc(event_size); > + image_load_event = calloc(1, event_size); > if (!image_load_event) > return EFI_OUT_OF_RESOURCES; > > @@ -875,10 +874,8 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, > goto out; > } > > - if (device_path_length > 0) { > - memcpy(image_load_event->device_path, device_path, > - device_path_length); > - } > + /* device_path_length might be zero */ > + memcpy(image_load_event->device_path, device_path, device_path_length); > > ret = tcg2_agile_log_append(pcr_index, event_type, &digest_list, > event_size, (u8 *)image_load_event); > -- > 2.33.0 >