]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
tracing: Use str_has_prefix() instead of using fixed sizes
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 20 Dec 2018 18:20:07 +0000 (13:20 -0500)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Sun, 23 Dec 2018 03:51:54 +0000 (22:51 -0500)
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: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/trace.c
kernel/trace/trace_events.c
kernel/trace/trace_events_hist.c
kernel/trace/trace_probe.c
kernel/trace/trace_stack.c

index 5afcfecb4bc28fa8ff80304e8618281742cf28ef..eac2824a18abef340796bca9d92570b4fdd0bcee 100644 (file)
@@ -4411,7 +4411,7 @@ static int trace_set_options(struct trace_array *tr, char *option)
 
        cmp = strstrip(option);
 
-       if (strncmp(cmp, "no", 2) == 0) {
+       if (str_has_prefix(cmp, "no")) {
                neg = 1;
                cmp += 2;
        }
index bd0162c0467c8d7f5c06d80d0139cca7cf03a48c..5b3b0c3c8a47e581483818e270af391fd0ef1d57 100644 (file)
@@ -1251,7 +1251,7 @@ static int f_show(struct seq_file *m, void *v)
         */
        array_descriptor = strchr(field->type, '[');
 
-       if (!strncmp(field->type, "__data_loc", 10))
+       if (str_has_prefix(field->type, "__data_loc"))
                array_descriptor = NULL;
 
        if (!array_descriptor)
index 9d590138f870e4b7d6b5061d9088667bd8604e7b..0d878dcd1e4b02082926ba2c86341768e9e29a90 100644 (file)
@@ -518,7 +518,7 @@ static int synth_event_define_fields(struct trace_event_call *call)
 
 static bool synth_field_signed(char *type)
 {
-       if (strncmp(type, "u", 1) == 0)
+       if (str_has_prefix(type, "u"))
                return false;
 
        return true;
index ff86417c01493e00dddafbfd6d4a60b95107fe4b..541375737403585a428805997f51d2f67c38eebf 100644 (file)
@@ -194,7 +194,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
                        code->op = FETCH_OP_RETVAL;
                else
                        ret = -EINVAL;
-       } else if (strncmp(arg, "stack", 5) == 0) {
+       } else if (str_has_prefix(arg, "stack")) {
                if (arg[5] == '\0') {
                        code->op = FETCH_OP_STACKP;
                } else if (isdigit(arg[5])) {
@@ -213,7 +213,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
 #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
        } else if (((flags & TPARG_FL_MASK) ==
                    (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) &&
-                  strncmp(arg, "arg", 3) == 0) {
+                  str_has_prefix(arg, "arg")) {
                if (!isdigit(arg[3]))
                        return -EINVAL;
                ret = kstrtoul(arg + 3, 10, &param);
index e2a153fc1afc37f9e5a96729ba899207925d048d..3641f28c343f1e3e30490a39f687b12cb65cdb9a 100644 (file)
@@ -448,7 +448,7 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
 
 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);
 
        stack_tracer_enabled = 1;