All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: "Simon Glass" <sjg@chromium.org>, "Stefan Roese" <sr@denx.de>,
	"Pali Rohár" <pali@kernel.org>
Cc: u-boot@lists.denx.de, "Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH 3/5] env: Simplify env_get_default()
Date: Thu, 28 Oct 2021 05:28:08 +0200	[thread overview]
Message-ID: <20211028032810.18146-4-kabel@kernel.org> (raw)
In-Reply-To: <20211028032810.18146-1-kabel@kernel.org>

From: Marek Behún <marek.behun@nic.cz>

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 <marek.behun@nic.cz>
---
 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


  parent reply	other threads:[~2021-10-28  3:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28  3:28 [PATCH 0/5] Board specific runtime determined default env Marek Behún
2021-10-28  3:28 ` [PATCH 1/5] env: Don't set ready flag if import failed in env_set_default() Marek Behún
2021-10-29  3:17   ` Simon Glass
2021-10-28  3:28 ` [PATCH 2/5] env: Fix env_get() when returning empty string using env_get_f() Marek Behún
2021-10-29  3:17   ` Simon Glass
2021-10-29  8:51     ` Marek Behún
2021-10-29  9:03     ` Pali Rohár
2021-10-31 13:07       ` Simon Glass
2021-10-31 15:27         ` Marek Behún
2021-10-28  3:28 ` Marek Behún [this message]
2021-10-29  3:17   ` [PATCH 3/5] env: Simplify env_get_default() Simon Glass
2021-10-28  3:28 ` [PATCH 4/5] env: Add support for board specific special default environment Marek Behún
2021-10-29  3:17   ` Simon Glass
2021-10-29  8:57     ` Marek Behún
2021-10-31 13:07       ` Simon Glass
2021-10-28  3:28 ` [PATCH 5/5] arm: mvebu: Espressobin: Use new API for setting default env at runtime Marek Behún
2021-10-29  3:17   ` Simon Glass
2021-10-31 20:15   ` Pali Rohár
2021-11-02 14:57     ` Simon Glass
2021-11-03 10:48       ` Pali Rohár
2021-10-29  3:17 ` [PATCH 0/5] Board specific runtime determined default env Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211028032810.18146-4-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.