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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E3ECC433EF for ; Wed, 3 Nov 2021 23:24:14 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 69E43608FB for ; Wed, 3 Nov 2021 23:24:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 69E43608FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AC99A83658; Thu, 4 Nov 2021 00:23:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.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=kernel.org header.i=@kernel.org header.b="ON0lSxGW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71FB7835B9; Thu, 4 Nov 2021 00:23:47 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 570FF83645 for ; Thu, 4 Nov 2021 00:23:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 36A7E611C9; Wed, 3 Nov 2021 23:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635981820; bh=tUiwu/2iIBUHsyjrJvkxg/3QW3MQZ4TDnxkLcHi8ab8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ON0lSxGW7kXmVTCL9na+m4SVVPFiqIgTD3cWxBwfwSCd8LPnb4KwtDgvIB9nPJYAY fus9SCEZUS+mIoUEMIMYaem6wbzup5Ldk9vG/H4in6MIVRw4W0WNpwnCTIYxBmSdRY x0XkDMO2LyVKVgdaxbVMryBu0I3Locdhbve/Taq2yR9CItDgyzBGXReGRraxGCy1IM FaR6rS37pX8x77Uw1hTRQssxeiprdBXLJy/w0Q/kM52m7D6ptWxWS7l7+LkyNt/p7f 7gW/D8d8KGovBTAk0VK8pCpECV2YLGU6f341eRLIPs/NfkKWcBLrpIG1sRnTN/FC30 6X0D0N2yX7Cbg== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Simon Glass , =?UTF-8?q?Pali=20Roh=C3=A1r?= Cc: u-boot@lists.denx.de, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH v2 03/12] env: Simplify env_get_default() Date: Thu, 4 Nov 2021 00:23:23 +0100 Message-Id: <20211103232332.2737-4-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211103232332.2737-1-kabel@kernel.org> References: <20211103232332.2737-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn Instead of pretending that we don't have environment to force searching default environment in env_get_default(), get the data from the default_environment[] buffer directly. Signed-off-by: Marek BehĂșn Reviewed-by: Simon Glass --- env/common.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/env/common.c b/env/common.c index 757c5f9ecd..208e2adaa0 100644 --- a/env/common.c +++ b/env/common.c @@ -148,12 +148,10 @@ char *from_env(const char *envvar) return ret; } -/* - * Look up variable from environment for restricted C runtime env. - */ -int env_get_f(const char *name, char *buf, unsigned len) +static int env_get_from_linear(const char *env, const char *name, char *buf, + unsigned len) { - const char *env, *p, *end; + const char *p, *end; size_t name_len; if (name == NULL || *name == '\0') @@ -161,11 +159,6 @@ int env_get_f(const char *name, char *buf, unsigned len) name_len = strlen(name); - if (gd->env_valid == ENV_INVALID) - env = default_environment; - else - env = (const char *)gd->env_addr; - for (p = env; *p != '\0'; p = end + 1) { const char *value; unsigned res; @@ -193,6 +186,21 @@ int env_get_f(const char *name, char *buf, unsigned len) return -1; } +/* + * Look up variable from environment for restricted C runtime env. + */ +int env_get_f(const char *name, char *buf, unsigned len) +{ + const char *env; + + if (gd->env_valid == ENV_INVALID) + env = default_environment; + else + env = (const char *)gd->env_addr; + + return env_get_from_linear(env, name, buf, len); +} + /** * Decode the integer value of an environment variable and return it. * @@ -232,17 +240,12 @@ int env_get_yesno(const char *var) */ char *env_get_default(const char *name) { - char *ret_val; - unsigned long really_valid = gd->env_valid; - unsigned long real_gd_flags = gd->flags; - - /* Pretend that the image is bad. */ - gd->flags &= ~GD_FLG_ENV_READY; - gd->env_valid = ENV_INVALID; - ret_val = env_get(name); - gd->env_valid = really_valid; - gd->flags = real_gd_flags; - return ret_val; + if (env_get_from_linear(default_environment, name, + (char *)(gd->env_buf), + sizeof(gd->env_buf)) >= 0) + return (char *)(gd->env_buf); + + return NULL; } void env_set_default(const char *s, int flags) -- 2.32.0