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 0C681C4332F for ; Thu, 10 Nov 2022 11:36:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 655868511F; Thu, 10 Nov 2022 12:36:32 +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="KKl36GMx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0B9C85136; Thu, 10 Nov 2022 12:36:30 +0100 (CET) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 EC64F85082 for ; Thu, 10 Nov 2022 12:36:27 +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-wm1-x330.google.com with SMTP id p13-20020a05600c468d00b003cf8859ed1bso950036wmo.1 for ; Thu, 10 Nov 2022 03:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YW3Sg7Kr41REA7rDExtbPHd9jmggTAauLxFwwcG7eAk=; b=KKl36GMxg79omBDWVDhyIAgxfomX3vMmYDsJK9si94PPjcCqsijOWh6Am2RvyhFTrv kmAG/tQMiVn2PGu/gIImJQJPvrBbQO4OWP/FBe+Zq3ar+d5hnlohjjwwPtFFsdoi6SbJ 6R2y/4OEefe9xaBPWqefJ4jlrSXG4t6xOBH6ZK4Er8cM+MXe88vy52W7FCz6LE+63M+w SKWY07MmO0D7ZTTGpHWXaIieR+y5y2dL0VnUCHKL0cnLu9LTS6BIe9IBFtYymFSIMAJw SiELXbDnUew/IjT2AAUycDtm1a7zmt+SwmP2zCwIcsfeaogL/fXnAovNjUfXsmSe3cfF rCZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YW3Sg7Kr41REA7rDExtbPHd9jmggTAauLxFwwcG7eAk=; b=mmray8Pt9c1nJGCOmWZXEqFOyf+H6+yzV9EUfp605tkiRKNbVdF6vs1HFGJP+YhPtU meaXuQfutwQ5Dty44126lUV5gTvkwiNdBRtHopWKwBLahxgI+H4PWLAzCFdFar2IM6fd 1ArmWINKJAejlWh+PCzeOnEtyXBWrrgtMEx2XJKj6VQEeT6t6fGLnhEAWbozQlpvhsGO 0uzie+eH0/Hmohut20sSJJgINuP15Ii8wICMV5Idh6rR4kFTpZ3C+UHDHAgjFYVXLn5p YBvaOdbhpbt8r4IYi0Z9Cr5efcI1bcZjJycfgV+MaPdf5M0aLgJeNE+9mJqWk60IybLL 9uRQ== X-Gm-Message-State: ACrzQf0oTKI1+wZc5zQyjl5EukdG8opf3fzTC2R7Z9mhFW6EE5gk1p0I QzGTP/HudwHgzhL6Jr7xUgtZRGzz8sk72UA2 X-Google-Smtp-Source: AMsMyM7UoC0yMJmgU8MRdRq+WjGTkii/gIOOAt8q9j+eXPUI1xnFGGMr45we3pHCWiMOQkhdB9MAjw== X-Received: by 2002:a05:600c:15d6:b0:3cf:8e4b:957e with SMTP id v22-20020a05600c15d600b003cf8e4b957emr25860524wmf.118.1668080182635; Thu, 10 Nov 2022 03:36:22 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc35:4b7e:b46:e9a0:216f:aab5]) by smtp.gmail.com with ESMTPSA id c7-20020a1c3507000000b003c6f1732f65sm4470538wma.38.2022.11.10.03.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 03:36:22 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH] efi_loader: simplify efi_load_from_path Date: Thu, 10 Nov 2022 13:36:10 +0200 Message-Id: <20221110113610.231544-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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