From patchwork Thu Nov 10 11:36:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 623331 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp58333pvb; Thu, 10 Nov 2022 03:36:35 -0800 (PST) X-Google-Smtp-Source: AMsMyM4xjChfzxXhp0BfJl9UE1beU/HVMdKgi2MWSLWdLOHpnBfEf+BH9Rv/gVZ4HZIHtSqM8vaR X-Received: by 2002:a05:6402:90a:b0:458:ca4d:a2f8 with SMTP id g10-20020a056402090a00b00458ca4da2f8mr62406597edz.230.1668080195187; Thu, 10 Nov 2022 03:36:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668080195; cv=none; d=google.com; s=arc-20160816; b=yzMnoP09IfVn1pxEva1cYFscnyvNIDZRISArLRlMRhbDSwUtTDXN6w6T3SBNu2DEVQ dO3Bl/238tElEibfBv+IEUjZjJx/92moB3NUg2J9TarpLdzKreHKT7xW5DlqbIMyQiFx VIkUWWWVxKkIGNu/9wWOEcwcpkDbA4QMNfLgW3Lm6A0M+leVMQ22yc0Rzl3JnNeguArt ZRmzjIThdyO2Iy4mS2/zXDaxL+OEtW9B0vUTXl4J+cdariuvEn27Y/5Q2oX2kp2mhV2o n1Soy49kLKMWpXDO0/HllErkh1ZVZMm1glvuP2gdRR4bbdj0THSONV5Y/rCA6oYEsT7T W+QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=YW3Sg7Kr41REA7rDExtbPHd9jmggTAauLxFwwcG7eAk=; b=v7sZVGH0RPGwpLtJBKSKgamJBzuZpw7Wk9DpoavhdRMqX3iq3wRyniSi2/oX3bcHBB rwFL8ccpPUZXwpchClIqXeXaUzt2fjM73F45sgJxo2P/j14eRZW7DTe44cIij80B/3xB uI32ChgCbZdnuA2isc3QL2XLH28zyZNHMghkqI9uON0N9HuJhgh9rNY1byvLGcwDCxqx 37WjlzHvih7njNiZ026dzz/3yQ7plGI3eWLKQYWsAQr+UsvPeOU0ZDoeu0fQHzFM3507 q3WcDUNfo/Ji3V4sEcWeJlKvzm+KkIwi50IncvwrkIJSYSNCkBV84gdUWbyNj9FsffD6 94ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KKl36GMx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id xh14-20020a170906da8e00b007801a579899si18137894ejb.448.2022.11.10.03.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 03:36:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KKl36GMx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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-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 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,