Skip to contentSkip to conversation

trace: clean up some code

PATCH New Amerigo Wang 1 participant 2 messages May 12, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace: clean up some code

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

Plus, kill an unnecessary local variable.

Cc Steven Rostedt <[email protected]>

---

kernel/trace/trace.c +1 -3
index a884c09..c31cc05 100644
@@ -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);
 }
 
kernel/trace/trace_stack.c +2 -8
index c750f65..007e435 100644
@@ -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 = {
#1 lore raw

PATCH 1/1 trace: fix a wrong usage of simple_read_from_buffer()

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

Cc Steven Rostedt <[email protected]>

---

kernel/trace/trace.c +1 -1
index a884c09..3a0bc70 100644
@@ -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);