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 B3824C433F5 for ; Wed, 23 Mar 2022 07:18:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2FC0683B2F; Wed, 23 Mar 2022 08:18:20 +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="PY2C6+XY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93F3E83B2F; Wed, 23 Mar 2022 08:18:18 +0100 (CET) Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 D717E83B11 for ; Wed, 23 Mar 2022 08:18:14 +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-pj1-x1033.google.com with SMTP id bx24-20020a17090af49800b001c6872a9e4eso901912pjb.5 for ; Wed, 23 Mar 2022 00:18:14 -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=CaPnt7mQuvN7VdUo06vXr97WqM8rMLZL5Zy3BhIW8Pk=; b=PY2C6+XYUN5xHxnFRGZkiT8X7EvY4DUg9o0ZuNN88BwCKZ77bNNKzT8d7tlG0iuDcD cogmoCgRh9FdPzXdTBhuDI+r7srOhllDn4SbnnA6PmNJ1qpo37yJ+9k44PHHN77gdy0t kORcmv3c+0cmece9n6eATV03yFpQ9b1oWIB3mNuC651EsonnK4Irdiq32qp0H9ddO+eo WJGAgAzfbu4gVdWZpgYSjlRsaShNkfMkPrttGqHD8cl+OpH8aYAhU2y7rgkY2UMLKHDH h0tDlO4xAj0H1OIIglxmqei7HuJItZk/4RWCq9dyj+mP+7QSp+0Q2+aa2sB6ylEuW4iE f+Lg== 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=CaPnt7mQuvN7VdUo06vXr97WqM8rMLZL5Zy3BhIW8Pk=; b=eo6I0ZJ7ittir3OW+cUVauu26LarIDOLCwwV/o4EEoz30VxKKlVc3u7LwGyr31eky0 UvRn8MpvqhAaGuaQZGj6xMfvl8+0GAUMFQXC5gIIkPZlHzTq0RPjX9tFUegHixTo4cRN Re7nCzNK8UFVC66SKe9xlsYEAt9JrE/jPG4p17oc/Mj5b/wIaxq/BcoiEvzxi6hTdEVv olGuxBU1vnvfnN5LU+T9Q4f84Y6B2OwFE2DqC8WfOMFYcNfXrG8Pht3eakZ0VpPwOWny BajsjMopOoU40z3NMfNbUbLmwMDME5stSKJ73dzawFgBn+5QrIHVyeNJk3Co3KFxUBIr H9TA== X-Gm-Message-State: AOAM532IFjmplKZJ/bELpO/1Gv5p0ZUVvjRKa78hH5djQ7yh86/apvmI 0foRVDh3JQJA8gqZwWxIZu0LTw== X-Google-Smtp-Source: ABdhPJy2LD7kSjdOh1HhAR49pIw2nVel+TF3IkNc5iUQCjDEzAD+ZBFcbTBiJrv0akr1lOy6rX+3uw== X-Received: by 2002:a17:90b:1a81:b0:1bc:c3e5:27b2 with SMTP id ng1-20020a17090b1a8100b001bcc3e527b2mr9791702pjb.20.1648019893209; Wed, 23 Mar 2022 00:18:13 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:2199:5d47:ea3f:788f]) by smtp.gmail.com with ESMTPSA id u25-20020a62ed19000000b004f140515d56sm25134498pfh.46.2022.03.23.00.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 00:18:12 -0700 (PDT) Date: Wed, 23 Mar 2022 16:18:09 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, Ilias Apalodimas Subject: Re: [PATCH v2 2/9] efi_loader: fix efi_dp_find_obj() Message-ID: <20220323071809.GD49108@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-3-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220319091148.142036-3-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:41AM +0100, Heinrich Schuchardt wrote: > efi_dp_find_obj() should not return any handle with a partially matching > device path If so, please describe so explicitly in the function's description. See below. > but the handle with the maximum matching device path. > > Signed-off-by: Heinrich Schuchardt > --- > v2: > new patch > --- > include/efi_loader.h | 4 +- > lib/efi_loader/efi_device_path.c | 110 +++++++++++++++++-------------- > 2 files changed, 63 insertions(+), 51 deletions(-) > > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 1ffcdfc485..6271d40125 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -730,8 +730,8 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp); > 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); > -struct efi_object *efi_dp_find_obj(struct efi_device_path *dp, > - struct efi_device_path **rem); > +efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, > + 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); > /* size of multi-instance device path excluding end node */ > diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c > index ddd5f132ec..aeb5264820 100644 > --- a/lib/efi_loader/efi_device_path.c > +++ b/lib/efi_loader/efi_device_path.c > @@ -159,69 +159,81 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) > return dp; > } > > -static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path, > - struct efi_device_path **rem) > +/** > + * find_handle() - find handle by device path > + * > + * If @rem is provided, the handle with the longest partial match is returned. > + * > + * @dp: device path to search > + * @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) > { > - struct efi_object *efiobj; > - efi_uintn_t dp_size = efi_dp_instance_size(dp); > + efi_handle_t handle, best_handle = NULL; > + efi_uintn_t len, best_len = 0; > + > + len = efi_dp_instance_size(dp); > > - list_for_each_entry(efiobj, &efi_obj_list, link) { > + list_for_each_entry(handle, &efi_obj_list, link) { > struct efi_handler *handler; > - struct efi_device_path *obj_dp; > + struct efi_device_path *dp_current; > + efi_uintn_t len_current; > efi_status_t ret; > > - ret = efi_search_protocol(efiobj, > - &efi_guid_device_path, &handler); > + ret = efi_search_protocol(handle, &efi_guid_device_path, > + &handler); > if (ret != EFI_SUCCESS) > continue; > - obj_dp = handler->protocol_interface; > - > - do { > - if (efi_dp_match(dp, obj_dp) == 0) { > - if (rem) { > - /* > - * Allow partial matches, but inform > - * the caller. > - */ > - *rem = ((void *)dp) + > - efi_dp_instance_size(obj_dp); > - return efiobj; > - } else { > - /* Only return on exact matches */ > - if (efi_dp_instance_size(obj_dp) == > - dp_size) > - return efiobj; > - } > - } > - > - obj_dp = efi_dp_shorten(efi_dp_next(obj_dp)); > - } while (short_path && obj_dp); > + dp_current = handler->protocol_interface; > + if (short_path) { > + dp_current = efi_dp_shorten(dp_current); > + if (!dp_current) > + continue; > + } > + len_current = efi_dp_instance_size(dp_current); > + if (rem) { > + if (len_current < len) > + continue; > + } else { > + if (len_current != len) > + continue; > + } > + if (memcmp(dp_current, dp, len)) > + continue; > + if (!rem) > + return handle; > + if (len_current > best_len) { > + best_len = len_current; > + best_handle = handle; > + *rem = (void*)((u8 *)dp + len_current); > + } > } > - > - return NULL; > + return best_handle; > } > > -/* > - * Find an efiobj from device-path, if 'rem' is not NULL, returns the > - * remaining part of the device path after the matched object. > +/** > + * efi_dp_find_obj() - find handle by device path > + * > + * If @rem is provided, the handle with the longest partial match is returned. What if @rem == NULL. > + * > + * @dp: device path to search > + * @rem: pointer to receive remaining device path > + * Return: matching handle > */ > -struct efi_object *efi_dp_find_obj(struct efi_device_path *dp, > - struct efi_device_path **rem) > +efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, > + struct efi_device_path **rem) The return type was also changed. Why not change the function name to, say, efi_dp_find_handle() "object" is an internal representation. -Takahiro Akashi > { > - struct efi_object *efiobj; > - > - /* Search for an exact match first */ > - efiobj = find_obj(dp, false, NULL); > - > - /* Then for a fuzzy match */ > - if (!efiobj) > - efiobj = find_obj(dp, false, rem); > + efi_handle_t handle; > > - /* And now for a fuzzy short match */ > - if (!efiobj) > - efiobj = find_obj(dp, true, rem); > + handle = find_handle(dp, false, rem); > + if (!handle) > + /* Match short form device path */ > + handle = find_handle(dp, true, rem); > > - return efiobj; > + return handle; > } > > /* > -- > 2.34.1 >