Skip to contentSkip to conversation

Return an error when setting a nonexistent tracer

PATCH Applied Frederic Weisbecker 3 participants 3 messages Oct 4, 2008 – Oct 5, 2008 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Return an error when setting a nonexistent tracer

When one try to set a nonexistent tracer, no error is returned as if the name of the tracer was correct.
We should return -EINVAL.

---
 kernel/trace/trace.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
kernel/trace/trace.c +10 -3
index 1cd2e81..9b30473 100644
@@ -2384,9 +2384,11 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 	struct tracer *t;
 	char buf[max_tracer_type_len+1];
 	int i;
+	size_t ret;
 
 	if (cnt > max_tracer_type_len)
 		cnt = max_tracer_type_len;
+	ret = cnt;
 
 	if (copy_from_user(&buf, ubuf, cnt))
 		return -EFAULT;
@@ -2402,7 +2404,11 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
 		if (strcmp(t->name, buf) == 0)
 			break;
 	}
-	if (!t || t == current_trace)
+	if (!t) {
+		ret = -EINVAL;
+		goto out;
+	}
+	if (t == current_trace)
 		goto out;
 
 	if (current_trace && current_trace->reset)
@@ -2415,9 +2421,10 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
  out:
 	mutex_unlock(&trace_types_lock);
 
-	filp->f_pos += cnt;
+	if (ret == cnt)
+		filp->f_pos += cnt;
 
-	return cnt;
+	return ret;
 }
 
 static ssize_t
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Frederic Weisbecker

When one try to set a nonexistent tracer, no error is returned as if the name of the tracer was correct.
We should return -EINVAL.

Thanks! This has been something I've been meaning to do for a long time but have never got around to doing it.

( I knew if I waited long enough, someone else would do it ;-)

Quoted 2 lines

-- Steve

Applied
#2 lore raw
Quoted 9 lines · Steven Rostedt
Quoted 3 lines · Frederic Weisbecker

When one try to set a nonexistent tracer, no error is returned as if the name of the tracer was correct.
We should return -EINVAL.

Thanks! This has been something I've been meaning to do for a long time but have never got around to doing it.

Quoted 6 lines

( I knew if I waited long enough, someone else would do it ;-)

Quoted 2 lines

applied to tip/tracing/core, thanks!

Ingo