Commit 2b90927c authored by Tom Zanussi's avatar Tom Zanussi Committed by Steven Rostedt (VMware)

tracing: Use seq_buf for building dynevent_cmd string

The dynevent_cmd commands that build up the command string don't need
to do that themselves - there's a seq_buf facility that does pretty
much the same thing those command are doing manually, so use it
instead.

Link: http://lkml.kernel.org/r/eb8a6e835c964d0ab8a38cbf5ffa60746b54a465.1580506712.git.zanussi@kernel.orgReviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarTom Zanussi <zanussi@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent e9260f62
...@@ -367,10 +367,8 @@ struct dynevent_cmd; ...@@ -367,10 +367,8 @@ struct dynevent_cmd;
typedef int (*dynevent_create_fn_t)(struct dynevent_cmd *cmd); typedef int (*dynevent_create_fn_t)(struct dynevent_cmd *cmd);
struct dynevent_cmd { struct dynevent_cmd {
char *buf; struct seq_buf seq;
const char *event_name; const char *event_name;
int maxlen;
int remaining;
unsigned int n_fields; unsigned int n_fields;
enum dynevent_type type; enum dynevent_type type;
dynevent_create_fn_t run_command; dynevent_create_fn_t run_command;
......
...@@ -247,8 +247,6 @@ int dynevent_arg_add(struct dynevent_cmd *cmd, ...@@ -247,8 +247,6 @@ int dynevent_arg_add(struct dynevent_cmd *cmd,
dynevent_check_arg_fn_t check_arg) dynevent_check_arg_fn_t check_arg)
{ {
int ret = 0; int ret = 0;
int delta;
char *q;
if (check_arg) { if (check_arg) {
ret = check_arg(arg); ret = check_arg(arg);
...@@ -256,14 +254,11 @@ int dynevent_arg_add(struct dynevent_cmd *cmd, ...@@ -256,14 +254,11 @@ int dynevent_arg_add(struct dynevent_cmd *cmd,
return ret; return ret;
} }
q = cmd->buf + (cmd->maxlen - cmd->remaining); ret = seq_buf_printf(&cmd->seq, " %s%c", arg->str, arg->separator);
if (ret) {
delta = snprintf(q, cmd->remaining, " %s%c", arg->str, arg->separator); pr_err("String is too long: %s%c\n", arg->str, arg->separator);
if (delta >= cmd->remaining) {
pr_err("String is too long: %s\n", arg->str);
return -E2BIG; return -E2BIG;
} }
cmd->remaining -= delta;
return ret; return ret;
} }
...@@ -297,8 +292,6 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd, ...@@ -297,8 +292,6 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd,
dynevent_check_arg_fn_t check_arg) dynevent_check_arg_fn_t check_arg)
{ {
int ret = 0; int ret = 0;
int delta;
char *q;
if (check_arg) { if (check_arg) {
ret = check_arg(arg_pair); ret = check_arg(arg_pair);
...@@ -306,23 +299,15 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd, ...@@ -306,23 +299,15 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd,
return ret; return ret;
} }
q = cmd->buf + (cmd->maxlen - cmd->remaining); ret = seq_buf_printf(&cmd->seq, " %s%c%s%c", arg_pair->lhs,
arg_pair->operator, arg_pair->rhs,
delta = snprintf(q, cmd->remaining, " %s%c", arg_pair->lhs, arg_pair->separator);
arg_pair->operator); if (ret) {
if (delta >= cmd->remaining) { pr_err("field string is too long: %s%c%s%c\n", arg_pair->lhs,
pr_err("field string is too long: %s\n", arg_pair->lhs); arg_pair->operator, arg_pair->rhs,
return -E2BIG; arg_pair->separator);
}
cmd->remaining -= delta; q += delta;
delta = snprintf(q, cmd->remaining, "%s%c", arg_pair->rhs,
arg_pair->separator);
if (delta >= cmd->remaining) {
pr_err("field string is too long: %s\n", arg_pair->rhs);
return -E2BIG; return -E2BIG;
} }
cmd->remaining -= delta;
return ret; return ret;
} }
...@@ -340,17 +325,12 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd, ...@@ -340,17 +325,12 @@ int dynevent_arg_pair_add(struct dynevent_cmd *cmd,
int dynevent_str_add(struct dynevent_cmd *cmd, const char *str) int dynevent_str_add(struct dynevent_cmd *cmd, const char *str)
{ {
int ret = 0; int ret = 0;
int delta;
char *q;
q = cmd->buf + (cmd->maxlen - cmd->remaining);
delta = snprintf(q, cmd->remaining, "%s", str); ret = seq_buf_puts(&cmd->seq, str);
if (delta >= cmd->remaining) { if (ret) {
pr_err("String is too long: %s\n", str); pr_err("String is too long: %s\n", str);
return -E2BIG; return -E2BIG;
} }
cmd->remaining -= delta;
return ret; return ret;
} }
...@@ -381,9 +361,7 @@ void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen, ...@@ -381,9 +361,7 @@ void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen,
{ {
memset(cmd, '\0', sizeof(*cmd)); memset(cmd, '\0', sizeof(*cmd));
cmd->buf = buf; seq_buf_init(&cmd->seq, buf, maxlen);
cmd->maxlen = maxlen;
cmd->remaining = cmd->maxlen;
cmd->type = type; cmd->type = type;
cmd->run_command = run_command; cmd->run_command = run_command;
} }
......
...@@ -1762,7 +1762,7 @@ static int synth_event_run_command(struct dynevent_cmd *cmd) ...@@ -1762,7 +1762,7 @@ static int synth_event_run_command(struct dynevent_cmd *cmd)
struct synth_event *se; struct synth_event *se;
int ret; int ret;
ret = trace_run_command(cmd->buf, create_or_delete_synth_event); ret = trace_run_command(cmd->seq.buffer, create_or_delete_synth_event);
if (ret) if (ret)
return ret; return ret;
......
...@@ -903,7 +903,7 @@ static int create_or_delete_trace_kprobe(int argc, char **argv) ...@@ -903,7 +903,7 @@ static int create_or_delete_trace_kprobe(int argc, char **argv)
static int trace_kprobe_run_command(struct dynevent_cmd *cmd) static int trace_kprobe_run_command(struct dynevent_cmd *cmd)
{ {
return trace_run_command(cmd->buf, create_or_delete_trace_kprobe); return trace_run_command(cmd->seq.buffer, create_or_delete_trace_kprobe);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment