From 83156682d6e027dd5ef49be55b676c401ca9f1b8 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Thu, 10 Jun 2021 13:57:35 +0200 Subject: lib/hardwaremain.c: Hide preprocessor guards in header The `location` member of `struct boot_state_callback` is conditionally guarded depending on `CONFIG(DEBUG_BOOT_STATE)` using preprocessor. It is probably intended to save some space when the `location` strings do not get printed. However, directly using the `location` member without any guards will cause a compile-time error. Plus, preprocessor-guarded code gets nasty really quickly. In order to minimise preprocessor usage, introduce the `bscb_location` inline helper function, which transforms the compile-time error into a link-time error. It is then possible to substitute preprocessor guards with an ordinary C `if` statement. Change-Id: I40b7f29f96ea96a5977b55760f0fcebf3a0df733 Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/55386 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak Reviewed-by: Raul Rangel Reviewed-by: Julius Werner --- src/include/bootstate.h | 10 ++++++++++ src/lib/hardwaremain.c | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/include/bootstate.h b/src/include/bootstate.h index 9fac70113e..a64446a4a1 100644 --- a/src/include/bootstate.h +++ b/src/include/bootstate.h @@ -2,6 +2,7 @@ #ifndef BOOTSTATE_H #define BOOTSTATE_H +#include #include #include /* Only declare main() when in ramstage. */ @@ -105,6 +106,15 @@ struct boot_state_callback { #endif }; +static inline const char *bscb_location(const struct boot_state_callback *bscb) +{ +#if CONFIG(DEBUG_BOOT_STATE) + return bscb->location; +#else + return dead_code_t(const char *); +#endif +} + #if CONFIG(DEBUG_BOOT_STATE) #define BOOT_STATE_CALLBACK_LOC __FILE__ ":" STRINGIFY(__LINE__) #define BOOT_STATE_CALLBACK_INIT_DEBUG .location = BOOT_STATE_CALLBACK_LOC, diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c index cd4a57e96e..7ab2ade912 100644 --- a/src/lib/hardwaremain.c +++ b/src/lib/hardwaremain.c @@ -274,10 +274,10 @@ static void bs_call_callbacks(struct boot_state *state, phase->callbacks = bscb->next; bscb->next = NULL; -#if CONFIG(DEBUG_BOOT_STATE) - printk(BIOS_DEBUG, "BS: callback (%p) @ %s.\n", - bscb, bscb->location); -#endif + if (CONFIG(DEBUG_BOOT_STATE)) { + printk(BIOS_DEBUG, "BS: callback (%p) @ %s.\n", + bscb, bscb_location(bscb)); + } bscb->callback(bscb->arg); continue; } -- cgit v1.2.3