]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: mtdparts: fix mtdparts variable presence confusion in mtdparts_init
authorLadislav Michl <ladis@linux-mips.org>
Tue, 12 Jul 2016 18:28:22 +0000 (20:28 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 22 Jul 2016 18:46:13 +0000 (14:46 -0400)
A private buffer is used to read mtdparts variable from non-relocated
environment. A pointer to that buffer is returned unconditionally,
confusing later test for variable presence in the environment.
Fix it by returning NULL when getenv_f fails.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
cmd/mtdparts.c

index 44b2c3a5a9fbfa55dd70505c126cc142f85de49c..3a88a10ba3471f1f6fdc0cd10a3dd5912115c2ab 100644 (file)
@@ -1720,11 +1720,13 @@ int mtdparts_init(void)
         * before the env is relocated, then we need to use our own stack
         * buffer.  gd->env_buf will be too small.
         */
-       if (gd->flags & GD_FLG_ENV_READY) {
+       if (gd->flags & GD_FLG_ENV_READY)
                parts = getenv("mtdparts");
-       } else {
-               parts = tmp_parts;
-               getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN);
+       else {
+               if (getenv_f("mtdparts", tmp_parts, MTDPARTS_MAXLEN) != -1)
+                       parts = tmp_parts;
+               else
+                       parts = NULL;
        }
        current_partition = getenv("partition");