summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2018-02-23 07:14:04 +0300
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2018-03-11 00:06:06 +0300
commit559d421267d1594c541143489d9ee9a869dc6093 (patch)
tree6eb5f0824c87cc6b8aeefb8ac67444e54ff8b86f
parenta0ff08fd4e3f8b1cbc18950a8bf1f9067f7e700a (diff)
downloadlinux-559d421267d1594c541143489d9ee9a869dc6093.tar.xz
tracing: Use trace_seq instead of open code string appending
The filter code does open code string appending to produce an error message. Instead it can be simplified by using trace_seq function helpers. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--kernel/trace/trace_events_filter.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 819a13c3e13c..f42442cd423a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -675,47 +675,36 @@ static int replace_filter_string(struct event_filter *filter,
return 0;
}
-static int append_filter_string(struct event_filter *filter,
- char *string)
-{
- int newlen;
- char *new_filter_string;
-
- if (WARN_ON(!filter->filter_string))
- return -EINVAL;
- newlen = strlen(filter->filter_string) + strlen(string) + 1;
- new_filter_string = kmalloc(newlen, GFP_KERNEL);
- if (!new_filter_string)
- return -ENOMEM;
-
- strcpy(new_filter_string, filter->filter_string);
- strcat(new_filter_string, string);
- kfree(filter->filter_string);
- filter->filter_string = new_filter_string;
-
- return 0;
-}
-
static void append_filter_err(struct filter_parse_state *ps,
struct event_filter *filter)
{
+ struct trace_seq *s;
int pos = ps->lasterr_pos;
- char *buf, *pbuf;
+ char *buf;
+ int len;
- buf = (char *)__get_free_page(GFP_KERNEL);
- if (!buf)
+ if (WARN_ON(!filter->filter_string))
return;
- append_filter_string(filter, "\n");
- memset(buf, ' ', PAGE_SIZE);
- if (pos > PAGE_SIZE - 128)
- pos = 0;
- buf[pos] = '^';
- pbuf = &buf[pos] + 1;
-
- sprintf(pbuf, "\nparse_error: %s\n", err_text[ps->lasterr]);
- append_filter_string(filter, buf);
- free_page((unsigned long) buf);
+ s = kmalloc(sizeof(*s), GFP_KERNEL);
+ if (!s)
+ return;
+ trace_seq_init(s);
+
+ len = strlen(filter->filter_string);
+ if (pos > len)
+ len = pos;
+
+ trace_seq_puts(s, filter->filter_string);
+ trace_seq_printf(s, "\n%*s", pos, "^");
+ trace_seq_printf(s, "\nparse_error: %s\n", err_text[ps->lasterr]);
+ trace_seq_putc(s, 0);
+ buf = kmemdup_nul(s->buffer, s->seq.len, GFP_KERNEL);
+ if (buf) {
+ kfree(filter->filter_string);
+ filter->filter_string = buf;
+ }
+ kfree(s);
}
static inline struct event_filter *event_filter(struct trace_event_file *file)