Commit bb71a2d9dcd9c53aa4d4b8e4d26c24d9b59b74c3

Authored by Simon Goldschmidt
Committed by Tom Rini
1 parent d024e992b3

dlmalloc: calloc: fix zeroing early allocations

When full malloc is enabled and SYS_MALLOC_F is also enabled, the simple
pre-reloc heap is used before relocation. In this case, calloc() uses
the MALLOC_ZERO macro to zero out the allocated memory. However, since
this macro is specially crafted for the dlmalloc implementation, it
does not always work for simple malloc.

For example, when allocating 16 bytes via simple malloc, only the first
12 bytes get zeroed out. The last 4 bytes will remain untouched.

This is a problem for DM drivers that are allocated before relocation:
memory allocated via 'platdata_auto_alloc_size' might not be set to
zero, resulting in bogus behaviour.

To fix this, use 'memset' instead of 'MALLOC_ZERO' to zero out memory
that compes from simple malloc.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

... ... @@ -2086,7 +2086,7 @@
2086 2086 {
2087 2087 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
2088 2088 if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
2089   - MALLOC_ZERO(mem, sz);
  2089 + memset(mem, 0, sz);
2090 2090 return mem;
2091 2091 }
2092 2092 #endif