[Concept,16/35] malloc: Add a Kconfig option for debugging malloc()
Commit Message
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(-)
@@ -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
@@ -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
@@ -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)