Skip to content

Commit

Permalink
tracing/profile: fix profile_disable vs module_unload
Browse files Browse the repository at this point in the history
If the correspoding module is unloaded before ftrace_profile_disable()
is called, event->profile_disable() won't be called, which can
cause oops:

  # insmod trace-events-sample.ko
  # perf record -f -a -e sample:foo_bar sleep 3 &
  # sleep 1
  # rmmod trace_events_sample
  # insmod trace-events-sample.ko
  OOPS!

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A9214E3.2070807@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Li Zefan authored and Steven Rostedt committed Sep 13, 2009
1 parent 4818d80 commit 558e654
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/trace/trace_event_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
*/

#include <linux/module.h>
#include "trace.h"

int ftrace_profile_enable(int event_id)
Expand All @@ -14,7 +15,8 @@ int ftrace_profile_enable(int event_id)

mutex_lock(&event_mutex);
list_for_each_entry(event, &ftrace_events, list) {
if (event->id == event_id && event->profile_enable) {
if (event->id == event_id && event->profile_enable &&
try_module_get(event->mod)) {
ret = event->profile_enable(event);
break;
}
Expand All @@ -32,6 +34,7 @@ void ftrace_profile_disable(int event_id)
list_for_each_entry(event, &ftrace_events, list) {
if (event->id == event_id) {
event->profile_disable(event);
module_put(event->mod);
break;
}
}
Expand Down

0 comments on commit 558e654

Please sign in to comment.