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 4C288C433F5 for ; Wed, 23 Mar 2022 07:26:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B21A683B2C; Wed, 23 Mar 2022 08:26:37 +0100 (CET) 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="mbyAK9Gu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 743C283B2F; Wed, 23 Mar 2022 08:26:35 +0100 (CET) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 44F9A83B11 for ; Wed, 23 Mar 2022 08:26:31 +0100 (CET) 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-pl1-x631.google.com with SMTP id x2so734341plm.7 for ; Wed, 23 Mar 2022 00:26:31 -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=zanSwldwTHpGqpSwXl+aJoET3YHSUbKnQfPb6ky2maw=; b=mbyAK9Gujw0C1kq8KVVYY9VsR4wo6acCDqTgRteTjeOqPVCun+k7tQooqct2ntKNVB 1X+3u0RCigH5R/uyeUQ0pTdmbogRMDYxLXCXItlSnUBMJTYoSkO5DVBpcl1RSGC0STWq 4psItr6asSWcuhaj2yNdpCTW+udWU2enSQgPgXwRZnRmFGbtTA1dLjcfBvzLhyFssqos Ge9s3h/yobGStiFK1sLJKkwd70Rqg+pDug0maRH7gWFpOsZ5L3YXQ7pvdB9MOctdrnD+ KBbpVIZp+3UhtInjlN8qSDBGBPx5IEDEKNNBiZq1qb9aE9s13zLWO+SvaQCdBDsKzn8h /5IA== 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=zanSwldwTHpGqpSwXl+aJoET3YHSUbKnQfPb6ky2maw=; b=ylAvTxnxfZf0dRsV2KFJviBkPpbbqZ6N5Qzty50gBCQIE+v7Mu26O6zdo2LSWKvlki FZ2a6YuwrmD6jSPurM6dA9qiwybRfT+iZu7/hiwdUpPUwisuRXzjJVbzJYWCMHxwaj9I IDK2nCueaXGcgsBC7BSHPwjXnu7zQynlYhNHxlxTnay6/XKA8LO9uBNxh6nCbOKSim72 fjFy+p/bAOTH8bE9MveaG6NeMSvkccjx/etAGJN4IO0QE2tjf9BBMN8Bw9iuK9YaDMuS ln805iwzLDPJqemina1fRRgR1VMqgu6Segp66kZd6qBAC/+Rt//PkMZrSvKF0g5g8vpG 2rgg== X-Gm-Message-State: AOAM533PD6Kd4Fdv2EARs2ibMuqbDhpHoQCjr5NfSm2j8qmCFgbXw+cJ ikkdOSoeWlu/KLVU6e22DGkiOg== X-Google-Smtp-Source: ABdhPJza/gu2kzJKkfV+rkXBysuLbCwipn9ebVz8v6ati5d1TmD/t7DHgmDlVPzaqhTxLcP/3ObfkA== X-Received: by 2002:a17:90b:1e0e:b0:1c7:5b03:1d8b with SMTP id pg14-20020a17090b1e0e00b001c75b031d8bmr8406087pjb.121.1648020389539; Wed, 23 Mar 2022 00:26:29 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:2199:5d47:ea3f:788f]) by smtp.gmail.com with ESMTPSA id j20-20020a62e914000000b004fa3bd9bef0sm19993626pfh.110.2022.03.23.00.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 00:26:29 -0700 (PDT) Date: Wed, 23 Mar 2022 16:26:26 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, Ilias Apalodimas Subject: Re: [PATCH v2 3/9] efi_loader: efi_dp_find_obj() add protocol check Message-ID: <20220323072626.GE49108@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , u-boot@lists.denx.de, Ilias Apalodimas References: <20220319091148.142036-1-heinrich.schuchardt@canonical.com> <20220319091148.142036-4-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220319091148.142036-4-heinrich.schuchardt@canonical.com> 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.5 at phobos.denx.de X-Virus-Status: Clean On Sat, Mar 19, 2022 at 10:11:42AM +0100, Heinrich Schuchardt wrote: > Let function efi_dp_find_obj() additionally check if a given protocol is > installed on the handle relating to the device-path. Please describe why you want to add another parameter to the function. Otherwise, we don't understand why the change is necessary. The caller can simply call efi_search_protocol() to determine whether the given protocol is installed or not on the handle. > Signed-off-by: Heinrich Schuchardt > --- > v2: > new patch > --- > include/efi_loader.h | 1 + > lib/efi_loader/efi_boottime.c | 2 +- > lib/efi_loader/efi_capsule.c | 2 +- > lib/efi_loader/efi_device_path.c | 23 ++++++++++++++++------- > lib/efi_loader/efi_disk.c | 2 +- > 5 files changed, 20 insertions(+), 10 deletions(-) > > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 6271d40125..1ae47a8713 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -731,6 +731,7 @@ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp); > int efi_dp_match(const struct efi_device_path *a, > const struct efi_device_path *b); > efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, > + const efi_guid_t *guid, > struct efi_device_path **rem); > /* get size of the first device path instance excluding end node */ > efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp); > diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c > index d0f3e05e70..a7bc371f54 100644 > --- a/lib/efi_loader/efi_boottime.c > +++ b/lib/efi_loader/efi_boottime.c > @@ -1750,7 +1750,7 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, > info->system_table = &systab; > > if (device_path) { > - info->device_handle = efi_dp_find_obj(device_path, NULL); > + info->device_handle = efi_dp_find_obj(device_path, NULL, NULL); > > dp = efi_dp_append(device_path, file_path); > if (!dp) { > diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c > index c8e2d510a5..3d80d98c1f 100644 > --- a/lib/efi_loader/efi_capsule.c > +++ b/lib/efi_loader/efi_capsule.c > @@ -681,7 +681,7 @@ static bool device_is_present_and_system_part(struct efi_device_path *dp) > { > efi_handle_t handle; > > - handle = efi_dp_find_obj(dp, NULL); > + handle = efi_dp_find_obj(dp, NULL, NULL); > if (!handle) > return false; > > diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c > index aeb5264820..0a8802903d 100644 > --- a/lib/efi_loader/efi_device_path.c > +++ b/lib/efi_loader/efi_device_path.c > @@ -160,17 +160,19 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) > } > > /** > - * find_handle() - find handle by device path > + * find_handle() - find handle by device path and installed protocol > * > * If @rem is provided, the handle with the longest partial match is returned. > * > * @dp: device path to search > + * @guid: GUID of protocol that must be installed on path or NULL > * @short_path: use short form device path for matching > * @rem: pointer to receive remaining device path > * Return: matching handle > */ > -static efi_handle_t find_handle(struct efi_device_path *dp, bool short_path, > - struct efi_device_path **rem) > +static efi_handle_t find_handle(struct efi_device_path *dp, > + const efi_guid_t *guid, bool short_path, > + struct efi_device_path **rem) > { > efi_handle_t handle, best_handle = NULL; > efi_uintn_t len, best_len = 0; > @@ -183,6 +185,11 @@ static efi_handle_t find_handle(struct efi_device_path *dp, bool short_path, > efi_uintn_t len_current; > efi_status_t ret; > > + if (guid) { > + ret = efi_search_protocol(handle, guid, &handler); > + if (ret != EFI_SUCCESS) > + continue; > + } > ret = efi_search_protocol(handle, &efi_guid_device_path, > &handler); > if (ret != EFI_SUCCESS) > @@ -195,13 +202,13 @@ static efi_handle_t find_handle(struct efi_device_path *dp, bool short_path, > } > len_current = efi_dp_instance_size(dp_current); > if (rem) { > - if (len_current < len) > + if (len_current > len) It looks a bug fix, but it's not related to this patch? -Takahiro Akashi > continue; > } else { > if (len_current != len) > continue; > } > - if (memcmp(dp_current, dp, len)) > + if (memcmp(dp_current, dp, len_current)) > continue; > if (!rem) > return handle; > @@ -220,18 +227,20 @@ static efi_handle_t find_handle(struct efi_device_path *dp, bool short_path, > * If @rem is provided, the handle with the longest partial match is returned. > * > * @dp: device path to search > + * @guid: GUID of protocol that must be installed on path or NULL > * @rem: pointer to receive remaining device path > * Return: matching handle > */ > efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, > + const efi_guid_t *guid, > struct efi_device_path **rem) > { > efi_handle_t handle; > > - handle = find_handle(dp, false, rem); > + handle = find_handle(dp, guid, false, rem); > if (!handle) > /* Match short form device path */ > - handle = find_handle(dp, true, rem); > + handle = find_handle(dp, guid, true, rem); > > return handle; > } > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c > index 45127d1768..d36a35d94f 100644 > --- a/lib/efi_loader/efi_disk.c > +++ b/lib/efi_loader/efi_disk.c > @@ -302,7 +302,7 @@ efi_fs_from_path(struct efi_device_path *full_path) > efi_free_pool(file_path); > > /* Get the EFI object for the partition */ > - efiobj = efi_dp_find_obj(device_path, NULL); > + efiobj = efi_dp_find_obj(device_path, NULL, NULL); > efi_free_pool(device_path); > if (!efiobj) > return NULL; > -- > 2.34.1 >