summaryrefslogtreecommitdiff
path: root/lib/trace.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-01-16 00:15:51 +0300
committerTom Rini <trini@konsulko.com>2023-02-11 20:22:35 +0300
commit852d4dbd70baa550cc5e8ef789aa719d30e94242 (patch)
treec17abd8e6c2cd3cff5e1411b7d5cc4dd5b582eb1 /lib/trace.c
parent80f91558a173fe841810ab6a7a0f70b52344ec76 (diff)
downloadu-boot-852d4dbd70baa550cc5e8ef789aa719d30e94242.tar.xz
trace: Detect an infinite loop
If something is wrong with a board's timer function such that it calls functions not marked with notrace, U-Boot will hang. Detect this, print a message and disable the trace. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/trace.c')
-rw-r--r--lib/trace.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/trace.c b/lib/trace.c
index bbc316af29..1091a5793a 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -39,6 +39,7 @@ struct trace_hdr {
int depth_limit; /* Depth limit to trace to */
int max_depth; /* Maximum depth seen so far */
int min_depth; /* Minimum depth seen so far */
+ bool trace_locked; /* Used to detect recursive tracing */
};
/* Pointer to start of trace buffer */
@@ -133,6 +134,14 @@ void notrace __cyg_profile_func_enter(void *func_ptr, void *caller)
if (trace_enabled) {
int func;
+ if (hdr->trace_locked) {
+ trace_enabled = 0;
+ puts("trace: recursion detected, disabling\n");
+ hdr->trace_locked = false;
+ return;
+ }
+
+ hdr->trace_locked = true;
trace_swap_gd();
add_ftrace(func_ptr, caller, FUNCF_ENTRY);
func = func_ptr_to_num(func_ptr);
@@ -146,6 +155,7 @@ void notrace __cyg_profile_func_enter(void *func_ptr, void *caller)
if (hdr->depth > hdr->max_depth)
hdr->max_depth = hdr->depth;
trace_swap_gd();
+ hdr->trace_locked = false;
}
}