public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace: clean up some code
@ 2009-05-12  7:11 Amerigo Wang
  2009-05-12  7:11 ` [PATCH] trace: fix a wrong usage of simple_read_from_buffer() Amerigo Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Amerigo Wang @ 2009-05-12  7:11 UTC (permalink / raw)
  To: linux-kernel; +Cc: Steven Rostedt, akpm, Amerigo Wang


64 bytes are big enough to hold "%ld" of any unsigned long, thus no need to
use snprintf.

Plus, kill an unnecessary local variable.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>

---
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a884c09..c31cc05 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2641,10 +2641,8 @@ tracing_max_lat_read(struct file *filp, char __user *ubuf,
 	char buf[64];
 	int r;
 
-	r = snprintf(buf, sizeof(buf), "%ld\n",
+	r = sprintf(buf, "%ld\n",
 		     *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
-	if (r > sizeof(buf))
-		r = sizeof(buf);
 	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
 }
 
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index c750f65..007e435 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -143,9 +143,7 @@ stack_max_size_read(struct file *filp, char __user *ubuf,
 	char buf[64];
 	int r;
 
-	r = snprintf(buf, sizeof(buf), "%ld\n", *ptr);
-	if (r > sizeof(buf))
-		r = sizeof(buf);
+	r = sprintf(buf, "%ld\n", *ptr);
 	return simple_read_from_buffer(ubuf, count, ppos, buf, r);
 }
 
@@ -301,11 +299,7 @@ static const struct seq_operations stack_trace_seq_ops = {
 
 static int stack_trace_open(struct inode *inode, struct file *file)
 {
-	int ret;
-
-	ret = seq_open(file, &stack_trace_seq_ops);
-
-	return ret;
+	return seq_open(file, &stack_trace_seq_ops);
 }
 
 static const struct file_operations stack_trace_fops = {

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] trace: fix a wrong usage of simple_read_from_buffer()
  2009-05-12  7:11 [PATCH] trace: clean up some code Amerigo Wang
@ 2009-05-12  7:11 ` Amerigo Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Amerigo Wang @ 2009-05-12  7:11 UTC (permalink / raw)
  To: linux-kernel; +Cc: Steven Rostedt, akpm, Amerigo Wang


The last argument of simple_read_from_buffer() is the amount of the
available bytes in the buffer, not the size of the buffer.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>

---
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a884c09..3a0bc70 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2125,7 +2125,7 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,
 		goto out_err;
 	}
 	len += sprintf(mask_str + len, "\n");
-	count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
+	count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
 
 out_err:
 	mutex_unlock(&tracing_cpumask_update_lock);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-12  7:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-12  7:11 [PATCH] trace: clean up some code Amerigo Wang
2009-05-12  7:11 ` [PATCH] trace: fix a wrong usage of simple_read_from_buffer() Amerigo Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox