From: Steven Rostedt Impact: clean up This patch converts the open coded retrieving of a word from user space to use copy_strtok_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 --- kernel/trace/trace.h | 2 + kernel/trace/trace_events.c | 69 +++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 6321917..e75b673 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -720,4 +720,6 @@ static inline void trace_branch_disable(void) } #endif /* CONFIG_BRANCH_TRACER */ +#define SPACES " \t\r\n" + #endif /* _LINUX_KERNEL_TRACE_H */ diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 3bcb9df..9e71755 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -80,62 +80,43 @@ 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_strtok_from_user(buf, ubuf, EVENT_BUF_SIZE, + cnt, &copied, SPACES); + if (ret < 0) + goto out_free; + + if (!copied) { + ret = cnt; + (*ppos) += cnt; + + /* TODO, handle split words */ + goto out_free; } - buf[i] = 0; - file->f_pos += read; + 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 -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/