tracing: Use str_has_prefix() instead of using fixed sizes

There are several instances of strncmp(str, "const", 123), where 123 is the
strlen of the const string to check if "const" is the prefix of str. But
this can be error prone. Use str_has_prefix() instead.
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 754481e6
...@@ -4411,7 +4411,7 @@ static int trace_set_options(struct trace_array *tr, char *option) ...@@ -4411,7 +4411,7 @@ static int trace_set_options(struct trace_array *tr, char *option)
cmp = strstrip(option); cmp = strstrip(option);
if (strncmp(cmp, "no", 2) == 0) { if (str_has_prefix(cmp, "no")) {
neg = 1; neg = 1;
cmp += 2; cmp += 2;
} }
......
...@@ -1251,7 +1251,7 @@ static int f_show(struct seq_file *m, void *v) ...@@ -1251,7 +1251,7 @@ static int f_show(struct seq_file *m, void *v)
*/ */
array_descriptor = strchr(field->type, '['); array_descriptor = strchr(field->type, '[');
if (!strncmp(field->type, "__data_loc", 10)) if (str_has_prefix(field->type, "__data_loc"))
array_descriptor = NULL; array_descriptor = NULL;
if (!array_descriptor) if (!array_descriptor)
......
...@@ -518,7 +518,7 @@ static int synth_event_define_fields(struct trace_event_call *call) ...@@ -518,7 +518,7 @@ static int synth_event_define_fields(struct trace_event_call *call)
static bool synth_field_signed(char *type) static bool synth_field_signed(char *type)
{ {
if (strncmp(type, "u", 1) == 0) if (str_has_prefix(type, "u"))
return false; return false;
return true; return true;
......
...@@ -194,7 +194,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, ...@@ -194,7 +194,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
code->op = FETCH_OP_RETVAL; code->op = FETCH_OP_RETVAL;
else else
ret = -EINVAL; ret = -EINVAL;
} else if (strncmp(arg, "stack", 5) == 0) { } else if (str_has_prefix(arg, "stack")) {
if (arg[5] == '\0') { if (arg[5] == '\0') {
code->op = FETCH_OP_STACKP; code->op = FETCH_OP_STACKP;
} else if (isdigit(arg[5])) { } else if (isdigit(arg[5])) {
...@@ -213,7 +213,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, ...@@ -213,7 +213,7 @@ 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)) &&
strncmp(arg, "arg", 3) == 0) { str_has_prefix(arg, "arg")) {
if (!isdigit(arg[3])) if (!isdigit(arg[3]))
return -EINVAL; return -EINVAL;
ret = kstrtoul(arg + 3, 10, &param); ret = kstrtoul(arg + 3, 10, &param);
......
...@@ -448,7 +448,7 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata; ...@@ -448,7 +448,7 @@ 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 (strncmp(str, "_filter=", 8) == 0) if (str_has_prefix(str, "_filter="))
strncpy(stack_trace_filter_buf, str+8, COMMAND_LINE_SIZE); strncpy(stack_trace_filter_buf, str+8, COMMAND_LINE_SIZE);
stack_tracer_enabled = 1; 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