[PATCH v4 04/44] spl: Avoid #ifdef with CONFIG_SPL_SYS_MALLOC
Simon Glass
sjg at chromium.org
Tue Sep 26 16:14:18 CEST 2023
Use IF_ENABLED_INT() to avoid needing to use the preprocessor.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v2)
Changes in v2:
- Improve readability by moving the size part to the header file
common/spl/spl.c | 8 ++++----
include/system-constants.h | 7 ++++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 657886dfe5b0..5cc86288145b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -754,10 +754,10 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
spl_set_bd();
-#if defined(CONFIG_SPL_SYS_MALLOC)
- mem_malloc_init(SPL_SYS_MALLOC_START, CONFIG_SPL_SYS_MALLOC_SIZE);
- gd->flags |= GD_FLG_FULL_MALLOC_INIT;
-#endif
+ if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
+ mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE);
+ gd->flags |= GD_FLG_FULL_MALLOC_INIT;
+ }
if (!(gd->flags & GD_FLG_SPL_INIT)) {
if (spl_init())
hang();
diff --git a/include/system-constants.h b/include/system-constants.h
index f0a191be590e..dca6a86b01f5 100644
--- a/include/system-constants.h
+++ b/include/system-constants.h
@@ -24,9 +24,14 @@
*/
#ifdef CONFIG_SPL_HAS_CUSTOM_MALLOC_START
#define SPL_SYS_MALLOC_START CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR
-#else
+#elif defined(CONFIG_SPL_BSS_START_ADDR)
#define SPL_SYS_MALLOC_START (CONFIG_SPL_BSS_START_ADDR + \
CONFIG_SPL_BSS_MAX_SIZE)
+#else
+/* feature not enabled: this value avoids compiler errors but is not used */
+#define SPL_SYS_MALLOC_START 0
#endif
+#define SPL_SYS_MALLOC_SIZE \
+ IF_ENABLED_INT(CONFIG_SPL_SYS_MALLOC, CONFIG_SPL_SYS_MALLOC_SIZE)
#endif
--
2.42.0.515.g380fc7ccd1-goog
More information about the U-Boot
mailing list