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 C8BCFC4332F for ; Thu, 10 Nov 2022 13:13:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B8BC85143; Thu, 10 Nov 2022 14:12:58 +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="RARJcDCP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 807E485143; Thu, 10 Nov 2022 14:12:56 +0100 (CET) Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (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 2B292850FF for ; Thu, 10 Nov 2022 14:12:52 +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=ilias.apalodimas@linaro.org Received: by mail-lj1-x22d.google.com with SMTP id z24so1132207ljn.4 for ; Thu, 10 Nov 2022 05:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VANnBSvP4I014wcdpf9JdgGtqoFHQD0PR72B+ddDTjA=; b=RARJcDCPAuanOmMQmXnKdh+EvGIjubN1bDgIK4AEOBLHAiyMqd25tC2wF1Lk1/T5XJ AztVQz9aAbrV5xBc41n+VCOQCSoY1DvPASuJenkk3MWagkjuD1SulJb9IEaXBX1P0v+Y /AvKCT90fhoY79F1UtMN7DvNqASO1GuFRHA0f4Z65Gh7EO4PXPYvOBZcAwfP3bZH70of NG4bzfH2cmWjYDk0jgRLo0o1BNyrp0ufNJnRNLI2n6Q/Gxkn4//ED1LhxtEt+PaLERXW y5OVTvuBpFWeLcL4wtWSOcKB9i0tOmdDb89y2jo3lhfUJWYLHjVYx3rfNCWhAMeeANv/ HahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VANnBSvP4I014wcdpf9JdgGtqoFHQD0PR72B+ddDTjA=; b=hUUiWQdLLt3K1wjLelOTO0UhrUsfs3+VsPquft194+V+y62ByjFZAc1YhuvOFqOhMf lIjjswCdVlVKOsUHC8zKto2tqwP2inh9ofybgyDcEU2rgiJ0NqCowPpIVOZJ3FlIUuo1 QqerIplvbGUG5QxFbAsoPpv1yesxcfcOJhIxfO2Jd8VN3DW9hAIwOqy8/AfV5yXHoOfw JHZaR9ghwyuRFkTH1ch6j2vdPq9oZSb70dziQVFBsRtDrCoX6iEkuV9iUvlztoe2k0pe qKD7tiQMNUzW6wOLleycqHbpLIJRUAE38F++ztQhN5hFiKnz4ePqrytUt2vSrR32uR4H BVmw== X-Gm-Message-State: ACrzQf1P0LCTxxbGySKNVqtCqdIGG/iGP847XtfmRRY5cg/XgcoLQBRr VCYyOg9ZAyhonMRSgctfIe5wNcK3buhXrzAszmnag6Y3LoM= X-Google-Smtp-Source: AMsMyM7IW2jtibpH3r2/iAXnIYbf2vYYkkzxLctRfNWKv2Bs96attjOJgKkbq9cdMpFqYnWqnoHTNTeDkxQ8N5N+84M= X-Received: by 2002:a2e:9f42:0:b0:277:1295:31ca with SMTP id v2-20020a2e9f42000000b00277129531camr8678487ljk.280.1668085971399; Thu, 10 Nov 2022 05:12:51 -0800 (PST) MIME-Version: 1.0 References: <20221110113610.231544-1-ilias.apalodimas@linaro.org> In-Reply-To: <20221110113610.231544-1-ilias.apalodimas@linaro.org> From: Ilias Apalodimas Date: Thu, 10 Nov 2022 15:12:15 +0200 Message-ID: Subject: Re: [PATCH] efi_loader: simplify efi_load_from_path To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Heinrich Schuchardt Content-Type: text/plain; charset="UTF-8" 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 Heinrich Please ignore this. As we discussed although this cleans up things considerably, it's not exactly what the spec describes. So let's keep the existing function. I've sent another patch cleaning up the EFI_CALL() iterations Thanks /Ilias On Thu, 10 Nov 2022 at 13:36, Ilias Apalodimas wrote: > > The current implementation efi_load_from_path is a bit confusing. > First of all it tries to check the device path to make sure it contains > the path to the device plus the media path with the filename and nothing in > between. But that should already be valid since U-Boot constructs those > device paths. > On top of that it tries to traverse the device path nodes and acquire the > file part by stepping through the nodes of the directory path until the > file is reached. We already have efi_dp_split_file_path() for that so > rewrite the function and clean it up to use existing code. > > Signed-off-by: Ilias Apalodimas > --- > lib/efi_loader/efi_file.c | 52 ++++++++++++--------------------------- > 1 file changed, 16 insertions(+), 36 deletions(-) > > diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c > index c96a7f7ca371..e1695ba309e4 100644 > --- a/lib/efi_loader/efi_file.c > +++ b/lib/efi_loader/efi_file.c > @@ -1104,53 +1104,33 @@ static const struct efi_file_handle efi_file_handle_protocol = { > struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp) > { > struct efi_simple_file_system_protocol *v; > - struct efi_file_handle *f; > + struct efi_device_path_file_path *mdp; > + struct efi_device_path *dev_dp, *file_dp; > + struct efi_file_handle *vol_handle, *file_handle = NULL; > efi_status_t ret; > > v = efi_fs_from_path(fp); > if (!v) > return NULL; > > - EFI_CALL(ret = v->open_volume(v, &f)); > + ret = efi_dp_split_file_path(fp, &dev_dp, &file_dp); > if (ret != EFI_SUCCESS) > return NULL; > + efi_free_pool(dev_dp); > > - /* Skip over device-path nodes before the file path. */ > - while (fp && !EFI_DP_TYPE(fp, MEDIA_DEVICE, FILE_PATH)) > - fp = efi_dp_next(fp); > - > - /* > - * Step through the nodes of the directory path until the actual file > - * node is reached which is the final node in the device path. > - */ > - while (fp) { > - struct efi_device_path_file_path *fdp = > - container_of(fp, struct efi_device_path_file_path, dp); > - struct efi_file_handle *f2; > - u16 *filename; > - > - if (!EFI_DP_TYPE(fp, MEDIA_DEVICE, FILE_PATH)) { > - printf("bad file path!\n"); > - f->close(f); > - return NULL; > - } > - > - filename = u16_strdup(fdp->str); > - if (!filename) > - return NULL; > - EFI_CALL(ret = f->open(f, &f2, filename, > - EFI_FILE_MODE_READ, 0)); > - free(filename); > - if (ret != EFI_SUCCESS) > - return NULL; > - > - fp = efi_dp_next(fp); > - > - EFI_CALL(f->close(f)); > - f = f2; > + ret = efi_open_volume_int(v, &vol_handle); > + if (ret != EFI_SUCCESS) { > + efi_free_pool(file_dp); > + return NULL; > } > > - return f; > + mdp = (struct efi_device_path_file_path *)file_dp; > + /* we don't really care about the ret here *file_handle will be NULL */ > + ret = efi_file_open_int(vol_handle, &file_handle, mdp->str, EFI_FILE_MODE_READ, 0); > + efi_free_pool(file_dp); > + efi_file_close_int(vol_handle); > + > + return file_handle; > } > > efi_status_t efi_open_volume_int(struct efi_simple_file_system_protocol *this, > -- > 2.38.1 >