tracing: Use the return of str_has_prefix() to remove open coded numbers

There are several locations that compare constants to the beginning of
string variables to determine what commands should be done, then the
constant length is used to index into the string. This is error prone as the
hard coded numbers have to match the size of the constants. Instead, use the
len returned from str_has_prefix() and remove the open coded string length
sizes.

Cc: Joe Perches <joe@perches.com>
Acked-by: Masami  Hiramatsu <mhiramat@kernel.org> (for trace_probe part)
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 036876fa
...@@ -4408,13 +4408,15 @@ static int trace_set_options(struct trace_array *tr, char *option) ...@@ -4408,13 +4408,15 @@ static int trace_set_options(struct trace_array *tr, char *option)
int neg = 0; int neg = 0;
int ret; int ret;
size_t orig_len = strlen(option); size_t orig_len = strlen(option);
int len;
cmp = strstrip(option); cmp = strstrip(option);
if (str_has_prefix(cmp, "no")) { len = str_has_prefix(cmp, "no");
if (len)
neg = 1; neg = 1;
cmp += 2;
} cmp += len;
mutex_lock(&trace_types_lock); mutex_lock(&trace_types_lock);
......
...@@ -186,19 +186,20 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup, ...@@ -186,19 +186,20 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
static int parse_probe_vars(char *arg, const struct fetch_type *t, static int parse_probe_vars(char *arg, const struct fetch_type *t,
struct fetch_insn *code, unsigned int flags) struct fetch_insn *code, unsigned int flags)
{ {
int ret = 0;
unsigned long param; unsigned long param;
int ret = 0;
int len;
if (strcmp(arg, "retval") == 0) { if (strcmp(arg, "retval") == 0) {
if (flags & TPARG_FL_RETURN) if (flags & TPARG_FL_RETURN)
code->op = FETCH_OP_RETVAL; code->op = FETCH_OP_RETVAL;
else else
ret = -EINVAL; ret = -EINVAL;
} else if (str_has_prefix(arg, "stack")) { } else if ((len = str_has_prefix(arg, "stack"))) {
if (arg[5] == '\0') { if (arg[len] == '\0') {
code->op = FETCH_OP_STACKP; code->op = FETCH_OP_STACKP;
} else if (isdigit(arg[5])) { } else if (isdigit(arg[len])) {
ret = kstrtoul(arg + 5, 10, &param); ret = kstrtoul(arg + len, 10, &param);
if (ret || ((flags & TPARG_FL_KERNEL) && if (ret || ((flags & TPARG_FL_KERNEL) &&
param > PARAM_MAX_STACK)) param > PARAM_MAX_STACK))
ret = -EINVAL; ret = -EINVAL;
...@@ -213,10 +214,10 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, ...@@ -213,10 +214,10 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
} else if (((flags & TPARG_FL_MASK) == } else if (((flags & TPARG_FL_MASK) ==
(TPARG_FL_KERNEL | TPARG_FL_FENTRY)) && (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) &&
str_has_prefix(arg, "arg")) { (len = str_has_prefix(arg, "arg"))) {
if (!isdigit(arg[3])) if (!isdigit(arg[len]))
return -EINVAL; return -EINVAL;
ret = kstrtoul(arg + 3, 10, &param); ret = kstrtoul(arg + len, 10, &param);
if (ret || !param || param > PARAM_MAX_STACK) if (ret || !param || param > PARAM_MAX_STACK)
return -EINVAL; return -EINVAL;
code->op = FETCH_OP_ARG; code->op = FETCH_OP_ARG;
......
...@@ -448,8 +448,10 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata; ...@@ -448,8 +448,10 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
static __init int enable_stacktrace(char *str) static __init int enable_stacktrace(char *str)
{ {
if (str_has_prefix(str, "_filter=")) int len;
strncpy(stack_trace_filter_buf, str+8, COMMAND_LINE_SIZE);
if ((len = str_has_prefix(str, "_filter=")))
strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
stack_tracer_enabled = 1; stack_tracer_enabled = 1;
last_stack_tracer_enabled = 1; last_stack_tracer_enabled = 1;
......
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