From patchwork Fri Nov 11 18:04:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 623748 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp944700pvb; Fri, 11 Nov 2022 10:04:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7DT4h90BDMtOMWgbU3+GBkLJNnDERGX4bG0jhUdCkfjE7ZI2/fxbdrBEASJc4ngKXtmZ9i X-Received: by 2002:a17:907:92f:b0:7ae:8b17:1520 with SMTP id au15-20020a170907092f00b007ae8b171520mr2783664ejc.358.1668189888644; Fri, 11 Nov 2022 10:04:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668189888; cv=none; d=google.com; s=arc-20160816; b=pvObzT1PrKbpCfGNabnCSli4HlyMHi0XiM4jdHLhy/0riRNsZv6kIwKL41RQMuoyk6 JxRqVT199VqZ5Hbopx0zmbjz/wEpw3Rk3Pf432wpjW5ys8tegvB9Wul8YsNwrISNVdR2 UpsCtFkhdfdcKyto2onAI63ZAXIeyTzIlbwxPF6qT5eL9hogpYt0CXbm+2rX+TPj3Kp2 BP2tnBj3e9ynrFoApnPIrG80mijSWhPIJTmweOh17MR96EHOZe9SvFIg8v8pg07Y0yv/ 5F3gaAZEF76Je8A+brOH2eNpwR+LIWQmxdvaBQC4/y3RKNqxCBhCBCP8iMhGTNSsQbDL aThw== 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=LTCkAcIXsFBqov35A+HzN/7DcV5eK095UnmRmkZtf74=; b=MEq7GozzOA7IPCEaDirWQk2gYxhAPar3IfJawxyZvnQLqTM3rTS9ZPVkAZfyesxiC/ L8wkSKR4wmlCAaPDkanS4zmA/lHje6EDcgfy5KGX+0zgbHLFOWuXqFSzPBZjyUVwyftp DQZuzVhDajEFB2IjxDepIxXGWenW2StIbsh5iUG8SB9R1zbQrme++rauqIIxiqqQRSAG gEmfzTwWRCi7iEN5myIBvGJNDO+2RgQ6o2TKnPBzb0wjVr5H7CpTLBouwuCfmgNiZFvs 1yisDxZMy861BUe9L/VebubYHoQQMIGuk1BUXd6aqWXGyDbJqbxYzt3W7owzjnfHj6Aj tBYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQHj5ZpP; 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 wt5-20020a170906ee8500b0073d8830e4c7si1972099ejb.954.2022.11.11.10.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 10:04:48 -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=dQHj5ZpP; 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 D3C9A84DF8; Fri, 11 Nov 2022 19:04:47 +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="dQHj5ZpP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B8B084FB2; Fri, 11 Nov 2022 19:04:46 +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-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 C3C4E8438C for ; Fri, 11 Nov 2022 19:04:43 +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-ed1-x52b.google.com with SMTP id u24so8631522edd.13 for ; Fri, 11 Nov 2022 10:04:43 -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=LTCkAcIXsFBqov35A+HzN/7DcV5eK095UnmRmkZtf74=; b=dQHj5ZpPNSfQZCmGl8qbNpD8bVgGVnhKR8xYFOFnVsIa9ekqYezVLotQ4ng2n1T2sv 5DWV0RpJ86WdwT1j5XevNLYS3FkVtWd3kpYONH6m1Q3oFkwSJYrVWFkpODxKOA4QhWw+ x+q2ooCteNzb6wahlLtyrdP+ip2Givf7xh6F9egakMZF+t1DPIgVnJmhR/4k5g2y9TtB ZoQVpuN72zMYImy1N71rNo7DPfiDWOG1YMfMwrmh0UoxGMEjyHBWIs1LfRbktW6XGI5n wvq6Uh13TQhbFO0ewW7FMdeSPqjir4aeNPY1w0cH7/O0Fm+3Fq4PCrRLOVRxttLytLeu hhDw== 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=LTCkAcIXsFBqov35A+HzN/7DcV5eK095UnmRmkZtf74=; b=fHt0qJKHDXEP3dPds8WPxU1GUQIt7KRO6GJDJf8YV/tYaTLVtxNSneBllbWEW/REe/ ijB+RsA6GzfJNodcb3vfLibJCWuWs35RbvtndRFzHTa0EbQGJ2xd81IE0kkwJ0HKHy+B I3/CftV3lwDoLcQtGkN3sArdx5/tX1IyV362L9Rzq1zfPdnal0nBqaT4mBYuIjNqi+Yc EiJmogEa3G7b9YDXLsJMKiRHaUHSdI3cY3ttBNzbvtIT2OqTM7OhnQqy9Aada2A1Nkr1 xDb0pjfVfX1d5wDPjm26vvWRbBY4bgG8plZ6G1B7TB3efpUIlC3n3IWg9rDiXKCltWj/ SuOA== X-Gm-Message-State: ANoB5pnShd9C4YbvbeHmUJFOWRsC9H+BaPLWs8QEoSlK+3ES5T8dY+Hf CSjAVtZPG23e4G2rKqcW2fxAqauyLFBlXy72 X-Received: by 2002:aa7:db46:0:b0:459:278b:7a8b with SMTP id n6-20020aa7db46000000b00459278b7a8bmr2454013edt.355.1668189883433; Fri, 11 Nov 2022 10:04:43 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc35:4b7e:abac:c110:8225:436a]) by smtp.gmail.com with ESMTPSA id la11-20020a170907780b00b007030c97ae62sm1095541ejc.191.2022.11.11.10.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 10:04:42 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Ilias Apalodimas , Heinrich Schuchardt Subject: [PATCH] efi_loader: replace a u16_strdup with alloc + memcpy Date: Fri, 11 Nov 2022 20:04:31 +0200 Message-Id: <20221111180431.1307444-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 Heinrich reports that on RISC-V unaligned access is emulated by OpenSBI which is very slow. Performance wise it's better if we skip the calls to u16_strdup() -- which in turn calls u16_strsize() and just allocate/copy the memory directly. The access to dp.length may still be unaligned, but that's way less than what u16_strsize() would do Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 750d380ad967..ff731db6cb8c 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -1128,6 +1128,7 @@ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp) container_of(fp, struct efi_device_path_file_path, dp); struct efi_file_handle *f2; u16 *filename; + size_t filename_sz; if (!EFI_DP_TYPE(fp, MEDIA_DEVICE, FILE_PATH)) { printf("bad file path!\n"); @@ -1140,9 +1141,14 @@ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp) * protocol member functions to be aligned. So memcpy it * unconditionally */ - filename = u16_strdup(fdp->str); + if (fdp->dp.length <= offsetof(struct efi_device_path_file_path, str)) + return NULL; + filename_sz = fdp->dp.length - + offsetof(struct efi_device_path_file_path, str); + filename = calloc(1, filename_sz); if (!filename) return NULL; + memcpy(filename, fdp->str, filename_sz); EFI_CALL(ret = f->open(f, &f2, filename, EFI_FILE_MODE_READ, 0)); free(filename);