[PATCH v3 15/38] spl: Avoid an #ifdef when printing gd->malloc_ptr

Simon Glass sjg at chromium.org
Sun Sep 24 21:25:00 CEST 2023


Use an accessor in the header file to avoid this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v3:
- Rebase on the new patch

Changes in v2:
- Use the same condition for both pieces to avoid possible problems

 common/spl/spl.c                  | 9 +++++----
 include/asm-generic/global_data.h | 6 ++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 8967a140041b..2c36caa856fa 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -864,10 +864,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	} else {
 		debug("Unsupported OS image.. Jumping nevertheless..\n");
 	}
-#if CONFIG_IS_ENABLED(SYS_MALLOC_F) && !defined(CONFIG_SPL_SYS_MALLOC_SIZE)
-	debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr,
-	      gd->malloc_ptr / 1024);
-#endif
+	if (CONFIG_IS_ENABLED(SYS_MALLOC_F) &&
+	    !IS_ENABLED(CONFIG_SPL_SYS_MALLOC_SIZE))
+		debug("SPL malloc() used 0x%lx bytes (%ld KB)\n",
+		      gd_malloc_ptr(), gd_malloc_ptr() / 1024);
+
 	bootstage_mark_name(get_bootstage_id(false), "end phase");
 #ifdef CONFIG_BOOTSTAGE_STASH
 	ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index f8fc87f1e46e..937fb12516c1 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -588,6 +588,12 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_set_pci_ram_top(val)
 #endif
 
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#define gd_malloc_ptr()		gd->malloc_ptr
+#else
+#define gd_malloc_ptr()		0L
+#endif
+
 /**
  * enum gd_flags - global data flags
  *
-- 
2.42.0.515.g380fc7ccd1-goog



More information about the U-Boot mailing list