All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 2/4] tracing: convert event_trace to use copy_word_from_user
Date: Wed, 25 Feb 2009 15:30:09 -0500	[thread overview]
Message-ID: <20090225203427.640471649@goodmis.org> (raw)
In-Reply-To: 20090225203007.582030664@goodmis.org

[-- Attachment #1: 0002-tracing-convert-event_trace-to-use-copy_word_from_u.patch --]
[-- Type: text/plain, Size: 2478 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Impact: clean up

This patch converts the open coded retrieving of a word from user
space to use copy_word_from_user.

Also removed a cnt < 0 check that Andrew Morton pointed out saying
that it was irrelevant since cnt is unsigned.

Also changed file->pos += to (*ppos) += which is the proper way
to modify positions of the file.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 kernel/trace/trace_events.c |   78 +++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 44 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 3bcb9df..91ed36c 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -80,62 +80,52 @@ static ssize_t
 ftrace_event_write(struct file *file, const char __user *ubuf,
 		   size_t cnt, loff_t *ppos)
 {
-	size_t read = 0;
-	int i, set = 1;
+	unsigned int copied;
+	size_t read;
 	ssize_t ret;
+	int set = 1;
 	char *buf;
-	char ch;
 
-	if (!cnt || cnt < 0)
+	if (!cnt)
 		return 0;
 
-	ret = get_user(ch, ubuf++);
-	if (ret)
-		return ret;
-	read++;
-	cnt--;
-
-	/* skip white space */
-	while (cnt && isspace(ch)) {
-		ret = get_user(ch, ubuf++);
-		if (ret)
-			return ret;
-		read++;
-		cnt--;
-	}
-
-	/* Only white space found? */
-	if (isspace(ch)) {
-		file->f_pos += read;
-		ret = read;
-		return ret;
-	}
-
 	buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
-	if (cnt > EVENT_BUF_SIZE)
-		cnt = EVENT_BUF_SIZE;
-
-	i = 0;
-	while (cnt && !isspace(ch)) {
-		if (!i && ch == '!')
-			set = 0;
-		else
-			buf[i++] = ch;
-
-		ret = get_user(ch, ubuf++);
-		if (ret)
-			goto out_free;
-		read++;
-		cnt--;
+	ret = copy_word_from_user(buf, ubuf, EVENT_BUF_SIZE,
+				  cnt, &copied, 1);
+
+	if (ret == -EAGAIN) {
+		/*
+		 * echo > set_event
+		 *  This will cause copy_word_from_user to return -EAGAIN
+		 *  but copied will be 0.
+		 */
+		if (!copied) {
+			ret = cnt;
+			(*ppos) += cnt;
+		}
+		/* TODO, handle split words */
+		goto out_free;
 	}
-	buf[i] = 0;
 
-	file->f_pos += read;
+	if (ret < 0)
+		goto out_free;
+
+	buf[copied] = 0;
+
+	if (buf[0] == '!')
+		set = 0;
+
+	(*ppos) += ret;
+	read = ret;
 
-	ret = ftrace_set_clr_event(buf, set);
+	/*
+	 * A little hack here. If set is true, we want to use buf.
+	 * Otherwise, we want to use buf+1 (to skip the '!').
+	 */
+	ret = ftrace_set_clr_event(buf + !set, set);
 	if (ret)
 		goto out_free;
 
-- 
1.5.6.5

-- 

  parent reply	other threads:[~2009-02-25 20:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-25 20:30 [PATCH 0/4] [git pull] for tip/tracing/ftrace Steven Rostedt
2009-02-25 20:30 ` [PATCH 1/4] uaccess: add copy_word_from_user Steven Rostedt
2009-02-25 21:39   ` Andrew Morton
2009-02-25 22:00     ` Steven Rostedt
2009-02-25 22:18     ` [PATCH][git pull] uaccess: add example to copy_word_from_user in comment Steven Rostedt
2009-02-25 21:40   ` [PATCH 1/4] uaccess: add copy_word_from_user Frederic Weisbecker
2009-02-25 21:54     ` Andrew Morton
2009-02-25 23:56   ` Andrew Morton
2009-02-26  1:46     ` Steven Rostedt
2009-02-26  5:34       ` Andrew Morton
2009-02-26  2:02   ` H. Peter Anvin
2009-02-26  2:10     ` Frederic Weisbecker
2009-02-26  2:13       ` H. Peter Anvin
2009-02-26  2:17     ` Steven Rostedt
2009-02-26  2:18       ` H. Peter Anvin
2009-02-26  5:36     ` Andrew Morton
2009-02-26  5:43       ` Steven Rostedt
2009-02-25 20:30 ` Steven Rostedt [this message]
2009-02-25 20:30 ` [PATCH 3/4] tracing: convert ftrace_regex_write to use copy_word_from_user Steven Rostedt
2009-02-25 20:30 ` [PATCH 4/4] tracing: convert ftrace_graph_write " 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=20090225203427.640471649@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=srostedt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.