public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>
Subject: [for-next-3.11][PATCH 12/12] tracing: Do not (ab)use trace_seq in event_id_read()
Date: Fri, 19 Jul 2013 10:12:36 -0400	[thread overview]
Message-ID: <20130719141450.253881041@goodmis.org> (raw)
In-Reply-To: 20130719141224.703522101@goodmis.org

[-- Attachment #1: 0012-tracing-Do-not-ab-use-trace_seq-in-event_id_read.patch --]
[-- Type: text/plain, Size: 1578 bytes --]

From: Oleg Nesterov <oleg@redhat.com>

event_id_read() has no reason to kmalloc "struct trace_seq"
(more than PAGE_SIZE!), it can use a small buffer instead.

Note: "if (*ppos) return 0" looks strange and even wrong,
simple_read_from_buffer() handles ppos != 0 case corrrectly.

And it seems that almost every user of trace_seq in this file
should be converted too. Unless you use seq_open(), trace_seq
buys nothing compared to the raw buffer, but it needs a bit
more memory and code.

Link: http://lkml.kernel.org/r/20130718184712.GA4786@redhat.com

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_events.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 76defd9..898f868 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -947,23 +947,14 @@ static ssize_t
 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
 {
 	struct ftrace_event_call *call = filp->private_data;
-	struct trace_seq *s;
-	int r;
+	char buf[32];
+	int len;
 
 	if (*ppos)
 		return 0;
 
-	s = kmalloc(sizeof(*s), GFP_KERNEL);
-	if (!s)
-		return -ENOMEM;
-
-	trace_seq_init(s);
-	trace_seq_printf(s, "%d\n", call->event.type);
-
-	r = simple_read_from_buffer(ubuf, cnt, ppos,
-				    s->buffer, s->len);
-	kfree(s);
-	return r;
+	len = sprintf(buf, "%d\n", call->event.type);
+	return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
 }
 
 static ssize_t
-- 
1.7.10.4



      parent reply	other threads:[~2013-07-19 14:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19 14:12 [for-next-3.11][PATCH 00/12] tracing: Cleanups and fixes Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 01/12] tracing: Use correct config guard CONFIG_STACK_TRACER Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 02/12] tracing: Use trace_seq_puts()/trace_seq_putc() where possible Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 03/12] tracing: Typo fix on ring buffer comments Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 04/12] tracing/function: Avoid perf_trace_buf_*() if event_function.perf_events is empty Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 05/12] tracing/syscall: Avoid perf_trace_buf_*() if sys_data->perf_events " Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 06/12] tracing/perf: Move the PERF_MAX_TRACE_SIZE check into perf_trace_buf_prepare() Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 07/12] tracing/kprobe: Wait for disabling all running kprobe handlers Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 08/12] tracing: Fix error handling to ensure instances can always be removed Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 09/12] tracing: Miscellaneous fixes for trace_array ref counting Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 10/12] tracing: Add ref_data to function and fgraph tracer structs Steven Rostedt
2013-07-19 14:12 ` [for-next-3.11][PATCH 11/12] tracing: Simplify the iteration logic in f_start/f_next Steven Rostedt
2013-07-19 14:12 ` Steven Rostedt [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=20130719141450.253881041@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.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