]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
env_nand.c: print error message and fail gracefully
authorWolfgang Denk <wd@denx.de>
Sun, 17 Jan 2010 04:50:26 +0000 (21:50 -0700)
committerScott Wood <scottwood@freescale.com>
Wed, 27 Jan 2010 20:22:41 +0000 (14:22 -0600)
env_nand.c would crash silently if a malloc() for the environment
buffers failed; make it print an error message and fail gracefully,
i. e. use the default environment then.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Acked-by: John Rigby <jcrigby@gmail.com>
common/env_nand.c

index ca631af195b1d30b9c575bc0d9368322e09e31eb..a15a9509025d201337d7c7b2fb2c4a874a46a21b 100644 (file)
@@ -298,6 +298,13 @@ void env_relocate_spec (void)
        tmp_env1 = (env_t *) malloc(CONFIG_ENV_SIZE);
        tmp_env2 = (env_t *) malloc(CONFIG_ENV_SIZE);
 
+       if ((tmp_env1 == NULL) || (tmp_env2 == NULL)) {
+               puts("Can't allocate buffers for environment\n");
+               free (tmp_env1);
+               free (tmp_env2);
+               return use_default();
+       }
+
        if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1))
                puts("No Valid Environment Area Found\n");
        if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2))