From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Joe Perches <joe@perches.com>, Namhyung Kim <namhyung@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
linux-sh@vger.kernel.org
Subject: [for-next][PATCH 3/5] tracing: Use str_has_prefix() instead of using fixed sizes
Date: Sat, 22 Dec 2018 11:20:10 -0500 [thread overview]
Message-ID: <20181222162856.822332549@goodmis.org> (raw)
In-Reply-To: 20181222162007.697862256@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
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.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 2 +-
kernel/trace/trace_events.c | 2 +-
kernel/trace/trace_events_hist.c | 2 +-
kernel/trace/trace_probe.c | 4 ++--
kernel/trace/trace_stack.c | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5afcfecb4bc2..eac2824a18ab 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -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;
}
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index bd0162c0467c..5b3b0c3c8a47 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -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)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 9d590138f870..0d878dcd1e4b 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -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;
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index ff86417c0149..541375737403 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -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, ¶m);
diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index e2a153fc1afc..3641f28c343f 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -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;
--
2.19.2
next prev parent reply other threads:[~2018-12-22 16:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-22 16:20 [for-next][PATCH 0/5] tracing: Add string_has_prefix() and usages Steven Rostedt
2018-12-22 16:20 ` [for-next][PATCH 1/5] string.h: Add str_has_prefix() helper function Steven Rostedt
2018-12-22 16:20 ` [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code Steven Rostedt
2018-12-22 18:01 ` Steven Rostedt
2018-12-22 18:02 ` Steven Rostedt
2018-12-22 18:03 ` Tom Zanussi
2018-12-23 3:53 ` Steven Rostedt
2018-12-23 16:38 ` Tom Zanussi
2018-12-23 3:32 ` Namhyung Kim
2018-12-22 16:20 ` Steven Rostedt [this message]
2018-12-22 16:20 ` [for-next][PATCH 4/5] tracing: Have the historgram use the result of str_has_prefix() for len of prefix Steven Rostedt
2018-12-23 3:35 ` Namhyung Kim
2018-12-23 16:40 ` Tom Zanussi
2018-12-22 16:20 ` [for-next][PATCH 5/5] tracing: Use the return of str_has_prefix() to remove open coded numbers Steven Rostedt
2018-12-23 3:23 ` Masami Hiramatsu
2018-12-23 3:46 ` Steven Rostedt
2018-12-23 0:55 ` [for-next][PATCH 0/5] tracing: Add string_has_prefix() and usages Steven Rostedt
2018-12-23 3:41 ` Namhyung Kim
2018-12-23 3:53 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181222162856.822332549@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=dalias@libc.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox