public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot]  [PATCH] env_mmc: avoid stack allocation for env
@ 2015-05-08 21:51 Tim Harvey
  2015-05-08 22:15 ` Marek Vasut
  0 siblings, 1 reply; 12+ messages in thread
From: Tim Harvey @ 2015-05-08 21:51 UTC (permalink / raw)
  To: u-boot

Allocating space for temporary env on the stack makes env_relocate_spec()
unsuitable for SPL environments which have very little stack.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 common/env_mmc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/common/env_mmc.c b/common/env_mmc.c
index 6c4ce2f..19a28da 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -213,13 +213,19 @@ void env_relocate_spec(void)
 	u32 offset1, offset2;
 	int read1_fail = 0, read2_fail = 0;
 	int crc1_ok = 0, crc2_ok = 0;
-	env_t *ep;
+	env_t *ep, *tmp_env1, *tmp_env2;
 	int ret;
 	int dev = CONFIG_SYS_MMC_ENV_DEV;
 	const char *errmsg = NULL;
 
-	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env1, 1);
-	ALLOC_CACHE_ALIGN_BUFFER(env_t, tmp_env2, 1);
+	tmp_env1 = memalign(CONFIG_SYS_CACHELINE_SIZE, CONFIG_ENV_SIZE);
+	tmp_env2 = memalign(CONFIG_SYS_CACHELINE_SIZE, CONFIG_ENV_SIZE);
+	if (tmp_env1 == NULL || tmp_env2 == NULL) {
+		puts("Can't allocate buffers for environment\n");
+		ret = 1;
+		errmsg = "!malloc() failed";
+		goto err;
+	}
 
 #ifdef CONFIG_SPL_BUILD
 	dev = 0;
@@ -287,6 +293,8 @@ void env_relocate_spec(void)
 	ret = 0;
 
 fini:
+	free(tmp_env1);
+	free(tmp_env2);
 	fini_mmc_for_env(mmc);
 err:
 	if (ret)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-08-02 21:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-08 21:51 [U-Boot] [PATCH] env_mmc: avoid stack allocation for env Tim Harvey
2015-05-08 22:15 ` Marek Vasut
2015-05-08 23:14   ` Tom Rini
2015-05-11 19:08     ` Tim Harvey
2015-05-12 15:14       ` Tom Rini
2015-05-13 19:58         ` Tim Harvey
2015-05-13 22:40           ` Tim Harvey
2015-05-14  2:02             ` Simon Glass
2015-05-14  3:22               ` Simon Glass
2015-05-14 13:11                 ` Tim Harvey
2015-08-02 21:29                   ` Simon Glass
2015-05-11 19:02   ` Tim Harvey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox