From: Marek BehĂșn Date: Wed, 3 Nov 2021 23:23:23 +0000 (+0100) Subject: env: Simplify env_get_default() X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=4e7c8b2a1cc77ed7267f21c383d3280496750791;p=u-boot.git env: Simplify env_get_default() 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 --- 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)