Skip to content

Commit cd458ba

Browse files
oleg-nesterovrostedt
authored andcommitted
tracing: Do not (ab)use trace_seq in event_id_read()
event_id_read() has no reason to kmalloc "struct trace_seq" (more than PAGE_SIZE!), it can use a small buffer instead. Note: "if (*ppos) return 0" looks strange and even wrong, simple_read_from_buffer() handles ppos != 0 case corrrectly. And it seems that almost every user of trace_seq in this file should be converted too. Unless you use seq_open(), trace_seq buys nothing compared to the raw buffer, but it needs a bit more memory and code. Link: http://lkml.kernel.org/r/20130718184712.GA4786@redhat.com Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 7710b63 commit cd458ba

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

‎kernel/trace/trace_events.c‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -947,23 +947,14 @@ static ssize_t
947947
event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
948948
{
949949
struct ftrace_event_call *call = filp->private_data;
950-
struct trace_seq *s;
951-
int r;
950+
char buf[32];
951+
int len;
952952

953953
if (*ppos)
954954
return 0;
955955

956-
s = kmalloc(sizeof(*s), GFP_KERNEL);
957-
if (!s)
958-
return -ENOMEM;
959-
960-
trace_seq_init(s);
961-
trace_seq_printf(s, "%d\n", call->event.type);
962-
963-
r = simple_read_from_buffer(ubuf, cnt, ppos,
964-
s->buffer, s->len);
965-
kfree(s);
966-
return r;
956+
len = sprintf(buf, "%d\n", call->event.type);
957+
return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
967958
}
968959

969960
static ssize_t

0 commit comments

Comments
 (0)