When events are enabled via the "enable" file within tracefs there is no get or put ref. Add these to ensure modules and dynamic events do not unload while the event is enabled via tracefs. Signed-off-by: Beau Belgrave <beaub@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/trace_events.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 0356cae0cf74..f0b17adba1bc 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -634,6 +634,8 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file, } call->class->reg(call, TRACE_REG_UNREGISTER, file); + + trace_event_put_ref(call); } /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */ if (file->flags & EVENT_FILE_FL_SOFT_MODE) @@ -659,7 +661,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file, } if (!(file->flags & EVENT_FILE_FL_ENABLED)) { - bool cmd = false, tgid = false; + bool cmd = false, tgid = false, put = false; /* Keep the event disabled, when going to SOFT_MODE. */ if (soft_disable) @@ -677,14 +679,22 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file, set_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags); } + if (!trace_event_try_get_ref(call)) + goto error_enabling; + + put = true; + ret = call->class->reg(call, TRACE_REG_REGISTER, file); if (ret) { +error_enabling: + pr_info("event trace: Could not enable event " + "%s\n", trace_event_name(call)); if (cmd) tracing_stop_cmdline_record(); if (tgid) tracing_stop_tgid_record(); - pr_info("event trace: Could not enable event " - "%s\n", trace_event_name(call)); + if (put) + trace_event_put_ref(call); break; } set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags); base-commit: 6c0f39e87b6ab1a3009e3a49d3e6f6db8dc756a8 -- 2.25.1