linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Dan Carpenter <dan.carpenter@oracle.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com,
	mingo@kernel.org, fweisbec@gmail.com, rostedt@goodmis.org,
	tglx@linutronix.de, dan.carpenter@oracle.com
Subject: [tip:perf/core] tracing: Check for allocation failure in __tracing_open()
Date: Wed, 18 Jul 2012 02:41:07 -0700	[thread overview]
Message-ID: <tip-93574fcc5b50cc7b8834698acb2ce947e5b6a5dc@git.kernel.org> (raw)
In-Reply-To: <20120711063507.GF11812@elgon.mountain>

Commit-ID:  93574fcc5b50cc7b8834698acb2ce947e5b6a5dc
Gitweb:     http://git.kernel.org/tip/93574fcc5b50cc7b8834698acb2ce947e5b6a5dc
Author:     Dan Carpenter <dan.carpenter@oracle.com>
AuthorDate: Wed, 11 Jul 2012 09:35:08 +0300
Committer:  Steven Rostedt <rostedt@goodmis.org>
CommitDate: Wed, 11 Jul 2012 19:56:26 -0400

tracing: Check for allocation failure in __tracing_open()

Clean up and return -ENOMEM on if the kzalloc() fails.

This also prevents a potential crash, as the pointer that failed to
allocate would be later used.

Link: http://lkml.kernel.org/r/20120711063507.GF11812@elgon.mountain

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 814ff30..a120f98 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2390,6 +2390,9 @@ __tracing_open(struct inode *inode, struct file *file)
 
 	iter->buffer_iter = kzalloc(sizeof(*iter->buffer_iter) * num_possible_cpus(),
 				    GFP_KERNEL);
+	if (!iter->buffer_iter)
+		goto release;
+
 	/*
 	 * We make a copy of the current tracer to avoid concurrent
 	 * changes on it while we are reading.
@@ -2451,6 +2454,7 @@ __tracing_open(struct inode *inode, struct file *file)
 	mutex_unlock(&trace_types_lock);
 	kfree(iter->trace);
 	kfree(iter->buffer_iter);
+release:
 	seq_release_private(inode, file);
 	return ERR_PTR(-ENOMEM);
 }

      reply	other threads:[~2012-07-18  9:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-11  6:35 [patch] tracing: check for allocation failure Dan Carpenter
2012-07-18  9:41 ` tip-bot for Dan Carpenter [this message]

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=tip-93574fcc5b50cc7b8834698acb2ce947e5b6a5dc@git.kernel.org \
    --to=dan.carpenter@oracle.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).