From: Simon Glass <simon.glass@canonical.com> Add a new CONFIG_MALLOC_DEBUG option to control malloc() debugging features. This replaces the direct UNIT_TEST check and allows enabling malloc debugging independently of whether UNIT_TEST is enabled. The option defaults to y when UNIT_TEST is enabled, preserving existing behaviour. Disable for RISC-V since it seems to have a size limitation. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- Kconfig | 8 ++++++++ common/dlmalloc.c | 2 +- include/malloc.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index 378ecfb1867..86276c89f38 100644 --- a/Kconfig +++ b/Kconfig @@ -337,6 +337,14 @@ config SYS_MALLOC_LEN This defines memory to be allocated for Dynamic allocation TODO: Use for other architectures +config MALLOC_DEBUG + bool "Enable malloc debugging" + default y if UNIT_TEST && !CPU_RISCV + help + Enable debugging features in the malloc implementation. This + enables additional assertions and the malloc_get_info() function + to retrieve memory-allocation statistics. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 004dafe4b3b..b5dc2b13dc6 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -568,7 +568,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP #ifdef __UBOOT__ -#if CONFIG_IS_ENABLED(UNIT_TEST) +#if CONFIG_IS_ENABLED(MALLOC_DEBUG) #define DEBUG 1 #endif diff --git a/include/malloc.h b/include/malloc.h index fd8a8ddcfaf..7e276d444ab 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -753,9 +753,9 @@ int initf_malloc(void); * malloc_get_info() - Get memory allocation statistics * * @info: Place to put the statistics - * Return: 0 on success, -ENOSYS if not available (DEBUG not defined) + * Return: 0 on success, -ENOSYS if not available (MALLOC_DEBUG not enabled) */ -#ifdef DEBUG +#if CONFIG_IS_ENABLED(MALLOC_DEBUG) int malloc_get_info(struct malloc_info *info); #else static inline int malloc_get_info(struct malloc_info *info) -- 2.43.0