summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-02-09 13:20:48 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-10 05:49:43 +0000
commitb1a173ea45a94368325440dd014417554c88918a (patch)
tree5222a0459bbc24856b77135ec911042ecddf621d
parent039c889e1435da921d2e18dc63ab96e4cf437a07 (diff)
downloadchrome-ec-b1a173ea45a94368325440dd014417554c88918a.tar.gz
panic: Tidy up the #ifdefs
Move the common code into a separate function. Add comments to the nesting. Use IS_ENABLED() where possible and drop the outer #ifdef around the C code, since the linker will throw it away automatically if it is not called. BUG=b:177604307 BRANCH=none TEST=verified no code-size change on volteer Change-Id: I61065d37fb6267097a2078493a4edfcdeea23819 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2686248 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--builtin/assert.h17
-rw-r--r--common/panic_output.c23
2 files changed, 22 insertions, 18 deletions
diff --git a/builtin/assert.h b/builtin/assert.h
index e58a450fa8..f51ea7b57a 100644
--- a/builtin/assert.h
+++ b/builtin/assert.h
@@ -27,7 +27,9 @@ extern noreturn void panic_assert_fail(const char *fname, int linenum);
if (!(cond)) \
panic_assert_fail(__FILE__, __LINE__); \
} while (0)
-#else
+
+#else /* !CONFIG_DEBUG_ASSERT_BRIEF */
+
extern noreturn void panic_assert_fail(const char *msg, const char *func,
const char *fname, int linenum);
#define ASSERT(cond) \
@@ -36,18 +38,21 @@ extern noreturn void panic_assert_fail(const char *msg, const char *func,
panic_assert_fail(#cond, __func__, __FILE__, \
__LINE__); \
} while (0)
-#endif
-#else
+#endif /* CONFIG_DEBUG_ASSERT_BRIEF */
+
+#else /* !CONFIG_DEBUG_ASSERT_REBOOTS */
+
#define ASSERT(cond) \
do { \
if (!(cond)) \
__asm("bkpt"); \
__builtin_unreachable(); \
} while (0)
-#endif
-#else
+#endif /* CONFIG_DEBUG_ASSERT_REBOOTS */
+
+#else /* !CONFIG_DEBUG_ASSERT */
#define ASSERT(cond)
-#endif
+#endif /* CONFIG_DEBUG_ASSERT */
/* This collides with cstdlib, so exclude it where cstdlib is supported. */
#ifndef assert
diff --git a/common/panic_output.c b/common/panic_output.c
index 66a39a60cc..cbec6c2f00 100644
--- a/common/panic_output.c
+++ b/common/panic_output.c
@@ -126,16 +126,20 @@ void panic_reboot(void)
system_reset(0);
}
-#ifdef CONFIG_DEBUG_ASSERT_REBOOTS
+/* Complete the processing of a panic, after the initial message is shown */
+static noreturn void complete_panic(int linenum)
+{
+ if (IS_ENABLED(CONFIG_SOFTWARE_PANIC))
+ software_panic(PANIC_SW_ASSERT, linenum);
+ else
+ panic_reboot();
+}
+
#ifdef CONFIG_DEBUG_ASSERT_BRIEF
void panic_assert_fail(const char *fname, int linenum)
{
panic_printf("\nASSERTION FAILURE at %s:%d\n", fname, linenum);
-#ifdef CONFIG_SOFTWARE_PANIC
- software_panic(PANIC_SW_ASSERT, linenum);
-#else
- panic_reboot();
-#endif
+ complete_panic(linenum);
}
#else
void panic_assert_fail(const char *msg, const char *func, const char *fname,
@@ -143,14 +147,9 @@ void panic_assert_fail(const char *msg, const char *func, const char *fname,
{
panic_printf("\nASSERTION FAILURE '%s' in %s() at %s:%d\n",
msg, func, fname, linenum);
-#ifdef CONFIG_SOFTWARE_PANIC
- software_panic(PANIC_SW_ASSERT, linenum);
-#else
- panic_reboot();
-#endif
+ complete_panic(linenum);
}
#endif
-#endif
void panic(const char *msg)
{