ftrace: add checks on ret stack in function graph
authorSteven Rostedt <srostedt@redhat.com>
Wed, 3 Dec 2008 04:50:06 +0000 (23:50 -0500)
committerIngo Molnar <mingo@elte.hu>
Wed, 3 Dec 2008 07:56:27 +0000 (08:56 +0100)
Import: robustness checks

Add more checks in the function graph code to detect errors and
perhaps print out better information if a bug happens.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/kernel/ftrace.c

index d278ad2ebda2c221122909c45214ad195196dcab..f98c4076a170173767d53d1bc876fd80ad154988 100644 (file)
@@ -420,6 +420,15 @@ static void pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret)
        int index;
 
        index = current->curr_ret_stack;
+
+       if (unlikely(index < 0)) {
+               ftrace_graph_stop();
+               WARN_ON(1);
+               /* Might as well panic, otherwise we have no where to go */
+               *ret = (unsigned long)panic;
+               return;
+       }
+
        *ret = current->ret_stack[index].ret;
        trace->func = current->ret_stack[index].func;
        trace->calltime = current->ret_stack[index].calltime;
@@ -427,6 +436,7 @@ static void pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret)
        trace->depth = index;
        barrier();
        current->curr_ret_stack--;
+
 }
 
 /*
@@ -442,6 +452,13 @@ unsigned long ftrace_return_to_handler(void)
        trace.rettime = cpu_clock(raw_smp_processor_id());
        ftrace_graph_return(&trace);
 
+       if (unlikely(!ret)) {
+               ftrace_graph_stop();
+               WARN_ON(1);
+               /* Might as well panic. What else to do? */
+               ret = (unsigned long)panic;
+       }
+
        return ret;
 }