From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Subject: [for-next][PATCH 6/6] tracing: Fix leak of ring buffer data when new instances creation fails
Date: Fri, 06 Jun 2014 12:30:40 -0400 [thread overview]
Message-ID: <20140606172105.000489056@goodmis.org> (raw)
In-Reply-To: 20140606163034.516780857@goodmis.org
[-- Attachment #1: 0005-tracing-Fix-leak-of-ring-buffer-data-when-new-instan.patch --]
[-- Type: text/plain, Size: 1906 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Yoshihiro Yunomae reported that the ring buffer data for a trace
instance does not get properly cleaned up when it fails. He proposed
a patch that manually cleaned the data up and addad a bunch of labels.
The labels are not needed because all trace array is allocated with
a kzalloc which initializes it to 0 and all kfree()s can take a NULL
pointer and will ignore it.
Adding a new helper function free_trace_buffers() that can also take
null buffers to free the buffers that were allocated by
allocate_trace_buffers().
Link: http://lkml.kernel.org/r/20140605223522.32311.31664.stgit@yunodevel
Reported-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/trace.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index e29edee1542a..26cfff38e2ab 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6232,6 +6232,25 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
return 0;
}
+static void free_trace_buffers(struct trace_array *tr)
+{
+ if (!tr)
+ return;
+
+ if (tr->trace_buffer.buffer) {
+ ring_buffer_free(tr->trace_buffer.buffer);
+ tr->trace_buffer.buffer = NULL;
+ free_percpu(tr->trace_buffer.data);
+ }
+
+#ifdef CONFIG_TRACER_MAX_TRACE
+ if (tr->max_buffer.buffer) {
+ ring_buffer_free(tr->max_buffer.buffer);
+ tr->max_buffer.buffer = NULL;
+ }
+#endif
+}
+
static int new_instance_create(const char *name)
{
struct trace_array *tr;
@@ -6290,8 +6309,7 @@ static int new_instance_create(const char *name)
return 0;
out_free_tr:
- if (tr->trace_buffer.buffer)
- ring_buffer_free(tr->trace_buffer.buffer);
+ free_trace_buffers(tr);
free_cpumask_var(tr->tracing_cpumask);
kfree(tr->name);
kfree(tr);
--
2.0.0.rc2
next prev parent reply other threads:[~2014-06-06 17:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-06 16:30 [for-next][PATCH 0/6] tracing: Hopefully the last updates for 3.16 merge window Steven Rostedt
2014-06-06 16:30 ` [for-next][PATCH 1/6] tracing: Introduce saved_cmdlines_size file Steven Rostedt
2014-06-06 16:30 ` [for-next][PATCH 2/6] tracing: Convert stddev into u64 in tracepoint benchmark Steven Rostedt
2014-06-06 16:30 ` [for-next][PATCH 3/6] tracing: Only calculate stats of tracepoint benchmarks for 2^32 times Steven Rostedt
2014-06-10 5:17 ` Namhyung Kim
2014-06-10 12:16 ` Steven Rostedt
2014-06-10 13:42 ` Steven Rostedt
2014-06-10 16:12 ` Steven Rostedt
2014-06-06 16:30 ` [for-next][PATCH 4/6] tracing: Return error if ftrace_trace_arrays list is empty Steven Rostedt
2014-06-10 5:20 ` Namhyung Kim
2014-06-10 13:42 ` Steven Rostedt
2014-06-06 16:30 ` [for-next][PATCH 5/6] tracing/kprobes: Avoid self tests if tracing is disabled on boot up Steven Rostedt
2014-06-06 16:30 ` Steven Rostedt [this message]
2014-06-10 5:25 ` [for-next][PATCH 6/6] tracing: Fix leak of ring buffer data when new instances creation fails Namhyung Kim
2014-06-10 15:58 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140606172105.000489056@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=yoshihiro.yunomae.ez@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox