[U-Boot] [PATCH] env_nand: fix incorrect size parameter to ALLOC_CACHE_ALIGN_BUFFER

From: Stephen Warren swarren@nvidia.com
The third parameter to ALLOC_CACHE_ALIGN_BUFFER is not size (as named), but rather count (number of elements of the type to allocate). The current code ends up allocating one copy of env_t for each byte in its size, which quite possibly ends up overflowing RAM.
This fixes a bug in commit 3801a15 "env_nand: align NAND buffers".
Reported-by: Prabhakar Lad prabhakar.csengg@gmail.com Signed-off-by: Stephen Warren swarren@nvidia.com --- common/env_nand.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/env_nand.c b/common/env_nand.c index e635472..79e8033 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -226,7 +226,7 @@ int saveenv(void) int saveenv(void) { int ret = 0; - ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, sizeof(env_t)); + ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); ssize_t len; char *res; nand_erase_options_t nand_erase_options;

Hi Stephen,
Thanks for the patch.
On Sat, Sep 8, 2012 at 12:45 AM, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
The third parameter to ALLOC_CACHE_ALIGN_BUFFER is not size (as named), but rather count (number of elements of the type to allocate). The current code ends up allocating one copy of env_t for each byte in its size, which quite possibly ends up overflowing RAM.
This fixes a bug in commit 3801a15 "env_nand: align NAND buffers".
Reported-by: Prabhakar Lad prabhakar.csengg@gmail.com Signed-off-by: Stephen Warren swarren@nvidia.com
Reported-by: Prabhakar Lad prabhakar.lad@ti.com
Regards, --Prabhakar Lad
common/env_nand.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/env_nand.c b/common/env_nand.c index e635472..79e8033 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -226,7 +226,7 @@ int saveenv(void) int saveenv(void) { int ret = 0;
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, sizeof(env_t));
ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); ssize_t len; char *res; nand_erase_options_t nand_erase_options;
-- 1.7.0.4

On Fri, Sep 07, 2012 at 09:15:33AM -0000, Stephen Warren wrote:
From: Stephen Warren swarren@nvidia.com
The third parameter to ALLOC_CACHE_ALIGN_BUFFER is not size (as named), but rather count (number of elements of the type to allocate). The current code ends up allocating one copy of env_t for each byte in its size, which quite possibly ends up overflowing RAM.
This fixes a bug in commit 3801a15 "env_nand: align NAND buffers".
Reported-by: Prabhakar Lad prabhakar.csengg@gmail.com Signed-off-by: Stephen Warren swarren@nvidia.com Reported-by: Prabhakar Lad prabhakar.lad@ti.com
Applied to u-boot/master, thanks!

On Fri, Sep 07, 2012 at 09:15:33AM -0000, Stephen Warren wrote:
From: Stephen Warren swarren@nvidia.com
The third parameter to ALLOC_CACHE_ALIGN_BUFFER is not size (as named), but rather count (number of elements of the type to allocate). The current code ends up allocating one copy of env_t for each byte in its size, which quite possibly ends up overflowing RAM.
This fixes a bug in commit 3801a15 "env_nand: align NAND buffers".
Reported-by: Prabhakar Lad prabhakar.csengg@gmail.com Signed-off-by: Stephen Warren swarren@nvidia.com Reported-by: Prabhakar Lad prabhakar.lad@ti.com
Applied to u-boot/master, thanks!
participants (3)
-
Prabhakar Lad
-
Stephen Warren
-
Tom Rini