mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Geyslan G. Bem" <geyslan@gmail.com>
To: kernel-br@googlegroups.com
Cc: "Geyslan G. Bem" <geyslan@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 2/2] tracing: fix referencing after memory freeing and refactors code
Date: Fri, 18 Oct 2013 17:59:42 -0300	[thread overview]
Message-ID: <1382129982-9668-2-git-send-email-geyslan@gmail.com> (raw)
In-Reply-To: <1382129982-9668-1-git-send-email-geyslan@gmail.com>

In 'system_tr_open()':
Fix possible 'dir' assignment after freeing it.

In both functions:
Restructures logic conditions testing 'tracing_is_disabled()'
return before the others tests.
Centralizes the exiting in accordance to Coding Style, Chapter 7.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
 kernel/trace/trace_events.c | 46 +++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 368a4d5..0f56ebf 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1060,7 +1060,10 @@ static int subsystem_open(struct inode *inode, struct file *filp)
 	struct event_subsystem *system = NULL;
 	struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */
 	struct trace_array *tr;
-	int ret;
+	int ret = -ENODEV;
+
+	if (tracing_is_disabled())
+		return ret;
 
 	/* Make sure the system still exists */
 	mutex_lock(&trace_types_lock);
@@ -1082,23 +1085,21 @@ static int subsystem_open(struct inode *inode, struct file *filp)
 	mutex_unlock(&trace_types_lock);
 
 	if (!system)
-		return -ENODEV;
+		return ret;
 
 	/* Some versions of gcc think dir can be uninitialized here */
 	WARN_ON(!dir);
 
 	/* Still need to increment the ref count of the system */
-	if (trace_array_get(tr) < 0) {
-		put_system(dir);
-		return -ENODEV;
-	}
+	ret = trace_array_get(tr);
+	if (ret)
+		goto err_get;
 
-	ret = tracing_open_generic(inode, filp);
-	if (ret < 0) {
-		trace_array_put(tr);
-		put_system(dir);
-	}
+	filp->private_data = dir;
+	return 0;
 
+err_get:
+	put_system(dir);
 	return ret;
 }
 
@@ -1106,28 +1107,29 @@ static int system_tr_open(struct inode *inode, struct file *filp)
 {
 	struct ftrace_subsystem_dir *dir;
 	struct trace_array *tr = inode->i_private;
-	int ret;
+	int ret = -ENODEV;
 
-	if (trace_array_get(tr) < 0)
-		return -ENODEV;
+	if (tracing_is_disabled())
+		return ret;
+
+	ret = trace_array_get(tr);
+	if (ret)
+		return ret;
 
 	/* Make a temporary dir that has no system but points to tr */
 	dir = kzalloc(sizeof(*dir), GFP_KERNEL);
 	if (!dir) {
-		trace_array_put(tr);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_dir;
 	}
 
 	dir->tr = tr;
 
-	ret = tracing_open_generic(inode, filp);
-	if (ret < 0) {
-		trace_array_put(tr);
-		kfree(dir);
-	}
-
 	filp->private_data = dir;
+	return 0;
 
+err_dir:
+	trace_array_put(tr);
 	return ret;
 }
 
-- 
1.8.4


  reply	other threads:[~2013-10-18 21:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-18 20:59 [PATCH 1/2] tracing: creates 'tracing_is_disabled()' Geyslan G. Bem
2013-10-18 20:59 ` Geyslan G. Bem [this message]
2013-11-06 16:17   ` [PATCH 2/2] tracing: fix referencing after memory freeing and refactors code Steven Rostedt
2013-11-06 19:08     ` Geyslan Gregório Bem
2013-10-19  0:09 ` [PATCH 1/2] tracing: creates 'tracing_is_disabled()' Steven Rostedt
2013-10-19  0:22   ` Geyslan Gregório Bem

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=1382129982-9668-2-git-send-email-geyslan@gmail.com \
    --to=geyslan@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=kernel-br@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.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®