"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

common: Tidy up how malloc() is inited

The call to malloc() is a bit strange. The naming of the arguments
suggests that an address is passed, but in fact it is a pointer, at
least in the board_init_r() function and SPL equivalent.

Update it to work as described. Add a function comment as well.

Note that this does adjustment does not extend into the malloc()
implementation itself, apart from changing mem_malloc_init(), since
there are lots of casts and pointers and integers are used
interchangeably.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

authored by

Simon Glass and committed by
Tom Rini
41fecdc9 09f5be61

+15 -8
+1 -2
common/board_r.c
··· 204 204 */ 205 205 start = gd->relocaddr - TOTAL_MALLOC_LEN; 206 206 gd_set_malloc_start(start); 207 - mem_malloc_init((ulong)map_sysmem(start, TOTAL_MALLOC_LEN), 208 - TOTAL_MALLOC_LEN); 207 + mem_malloc_init(start, TOTAL_MALLOC_LEN); 209 208 return 0; 210 209 } 211 210
+5 -3
common/dlmalloc.c
··· 16 16 #include <asm/global_data.h> 17 17 18 18 #include <malloc.h> 19 + #include <mapmem.h> 20 + #include <string.h> 19 21 #include <asm/io.h> 20 22 #include <valgrind/memcheck.h> 21 23 ··· 598 600 599 601 void mem_malloc_init(ulong start, ulong size) 600 602 { 601 - mem_malloc_start = start; 602 - mem_malloc_end = start + size; 603 - mem_malloc_brk = start; 603 + mem_malloc_start = (ulong)map_sysmem(start, size); 604 + mem_malloc_end = mem_malloc_start + size; 605 + mem_malloc_brk = mem_malloc_start; 604 606 605 607 #ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT 606 608 malloc_init();
+1 -3
common/spl/spl.c
··· 678 678 spl_set_bd(); 679 679 680 680 if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) { 681 - mem_malloc_init((ulong)map_sysmem(SPL_SYS_MALLOC_START, 682 - SPL_SYS_MALLOC_SIZE), 683 - SPL_SYS_MALLOC_SIZE); 681 + mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE); 684 682 gd->flags |= GD_FLG_FULL_MALLOC_INIT; 685 683 } 686 684 if (!(gd->flags & GD_FLG_SPL_INIT)) {
+8
include/malloc.h
··· 981 981 extern ulong mem_malloc_end; 982 982 extern ulong mem_malloc_brk; 983 983 984 + /** 985 + * mem_malloc_init() - Set up the malloc() pool 986 + * 987 + * Sets the region of memory to be used for all future calls to malloc(), etc. 988 + * 989 + * @start: Start address 990 + * @size: Size in bytes 991 + */ 984 992 void mem_malloc_init(ulong start, ulong size); 985 993 986 994 #ifdef __cplusplus