mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Jiri Kosina <jkosina@suse.cz>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Petr Mladek <pmladek@suse.com>
Subject: [PATCH 4/4] ftrace: Fixup trace_selftest_ops()
Date: Mon, 27 Jun 2016 15:54:37 +0200	[thread overview]
Message-ID: <1467035677-12193-5-git-send-email-pmladek@suse.com> (raw)
In-Reply-To: <1467035677-12193-1-git-send-email-pmladek@suse.com>

I was hunting a memory leak related to trace_selftest_ops() and found
two small mistakes there.

First, the dynamic trace must be freed in case of error. There was
one wrong goto target. It was even in the original commit
95950c2ecb31314ef ("ftrace: Add self-tests for multiple function
trace users").

Second, ftrace_init_array_ops() is called only when cnt > 1 but
but ftrace_reset_array_ops() is always called. It probably does
not harm but it is strange and might eventually hide a bug.
This was added by the commit 4104d326b670c2 ("ftrace: Remove global
function list and call function directly").

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 kernel/trace/trace_selftest.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
index b0f86ea77881..0b5ae79b5b0c 100644
--- a/kernel/trace/trace_selftest.c
+++ b/kernel/trace/trace_selftest.c
@@ -272,7 +272,7 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)
 		goto out_free;
 	if (cnt > 1) {
 		if (trace_selftest_test_global_cnt == 0)
-			goto out;
+			goto out_free;
 	}
 	if (trace_selftest_test_dyn_cnt == 0)
 		goto out_free;
@@ -298,9 +298,10 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)
 	unregister_ftrace_function(&test_probe1);
 	unregister_ftrace_function(&test_probe2);
 	unregister_ftrace_function(&test_probe3);
-	if (cnt > 1)
+	if (cnt > 1) {
 		unregister_ftrace_function(tr->ops);
-	ftrace_reset_array_ops(tr);
+		ftrace_reset_array_ops(tr);
+	}
 
 	/* Make sure everything is off */
 	reset_counts();
-- 
1.8.5.6

  parent reply	other threads:[~2016-06-27 13:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 13:54 [PATCH 0/4] ftrace: One more check on x86 and some small fixes Petr Mladek
2016-06-27 13:54 ` [PATCH 1/4] ftrace/x86: Make sure to modify 5-bite instructions Petr Mladek
2016-06-27 13:54 ` [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func Petr Mladek
2016-06-27 14:48   ` Steven Rostedt
2016-06-28 10:00     ` Petr Mladek
2016-06-27 13:54 ` [PATCH 3/4] ftrace: Always destroy trampoline when shutting down the trace Petr Mladek
2016-06-27 13:54 ` Petr Mladek [this message]
2016-06-28  5:22 ` [PATCH 0/4] ftrace: One more check on x86 and some small fixes Namhyung Kim
2016-06-28 19:17 ` Steven Rostedt
2016-06-29  8:22   ` Petr Mladek

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=1467035677-12193-5-git-send-email-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=fweisbec@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®