Skip to contentSkip to conversation

tracing: Add string_has_prefix() and usages

PATCH In review Steven Rostedt 4 participants 19 messages Dec 22, 2018 – Dec 23, 2018

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Add string_has_prefix() and usages

I hope everyone is OK with these changes. I pushed to linux-next but I'm willing to change them if there are still issues.

They ran through all my tests, althought zero-day-bot had a weird build regression in sh, that looks totally unrelated:

Regressions in current branch:

arch/sh/kernel/dwarf.c:107:26: error: 'dwarf_frame_reg' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:1209:0: error: unterminated argument list invoking macro "WARN_ON" arch/sh/kernel/dwarf.c:226:12: error: 'dwarf_read_encoded_value' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:306:26: error: 'dwarf_lookup_cie' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:38:27: error: 'dwarf_frame_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:399:12: error: 'dwarf_cfa_execute_insns' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:41:27: error: 'dwarf_reg_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:580:22: error: unused variable 'frame' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:581:20: error: unused variable 'cie' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:582:20: error: unused variable 'fde' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:583:20: error: unused variable 'reg' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:584:16: error: unused variable 'addr' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:622:3: error: expected ';' at end of input arch/sh/kernel/dwarf.c:622:3: error: expected declaration or statement at end of input arch/sh/kernel/dwarf.c:622:3: error: 'WARN_ON' undeclared (first use in this function); did you mean 'WMARK_LOW'?

Pushing to my for-next branch should kick off another run. Let's see if it reports that again. Unless someone knows why that happened?

-- Steve

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next

Head SHA1: 92b9de3e574bd874188a4e27a8830bb901a08ef8

Steven Rostedt (VMware) (5):
string.h: Add str_has_prefix() helper function
tracing: Use str_has_prefix() helper for histogram code
tracing: Use str_has_prefix() instead of using fixed sizes
tracing: Have the historgram use the result of str_has_prefix() for len of prefix
tracing: Use the return of str_has_prefix() to remove open coded numbers

----

 include/linux/string.h           | 20 ++++++++++++++++++++
 kernel/trace/trace.c             |  8 +++++---
 kernel/trace/trace_events.c      |  2 +-
 kernel/trace/trace_events_hist.c | 35 ++++++++++++++++++-----------------
 kernel/trace/trace_probe.c       | 17 +++++++++--------
 kernel/trace/trace_stack.c       |  6 ++++--
 6 files changed, 57 insertions(+), 31 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 string.h: Add str_has_prefix() helper function

From: "Steven Rostedt (VMware)" <[email protected]>

A discussion came up in the trace triggers thread about converting a bunch of:

strncmp(str, "const", sizeof("const") - 1)

use cases into a helper macro. It started with:

strncmp(str, const, sizeof(const) - 1)

But then Joe Perches mentioned that if a const is not used, the sizeof() will be the size of a pointer, which can be bad. And that gcc will optimize strlen("const") into "sizeof("const") - 1".

Thinking about this more, a quick grep in the kernel tree found several (thousands!) of cases that use this construct. A quick grep also revealed that there's probably several bugs in that use case. Some are that people forgot the "- 1" (which I found) and others could be that the constant for the sizeof is different than the constant (although, I haven't found any of those, but I also didn't look hard).

I figured the best thing to do is to create a helper macro and place it into include/linux/string.h. And go around and fix all the open coded versions of it later.

Note, gcc appears to optimize this when we make it into an always_inline static function, which removes a lot of issues that a macro produces.

---
 include/linux/string.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
include/linux/string.h +20 -0
index 27d0482e5e05..7927b875f80c 100644
@@ -456,4 +456,24 @@ static inline void memcpy_and_pad(void *dest, size_t dest_len,
 		memcpy(dest, src, dest_len);
 }
 
+/**
+ * str_has_prefix - Test if a string has a given prefix
+ * @str: The string to test
+ * @prefix: The string to see if @str starts with
+ *
+ * A common way to test a prefix of a string is to do:
+ *  strncmp(str, prefix, sizeof(prefix) - 1)
+ *
+ * But this can lead to bugs due to typos, or if prefix is a pointer
+ * and not a constant. Instead use str_has_prefix().
+ *
+ * Returns: 0 if @str does not start with @prefix
+         strlen(@prefix) if @str does start with @prefix
+ */
+static __always_inline size_t str_has_prefix(const char *str, const char *prefix)
+{
+	size_t len = strlen(prefix);
+	return strncmp(str, prefix, len) = 0 ? len : 0;
+}
+
 #endif /* _LINUX_STRING_H_ */
Signature · 1 line
2.19.2
author maintainer
#2 lore raw

PATCH 2/5 tracing: Use str_has_prefix() helper for histogram code

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

This can be prone to bugs due to typos or bad cut and paste. Use the str_has_prefix() helper macro instead that removes the need for having two copies of the constant string.

---
 kernel/trace/trace_events_hist.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/trace/trace_events_hist.c +14 -14
index c5448c103770..9d590138f870 100644
@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs)
 	if (attrs->n_actions >= HIST_ACTIONS_MAX)
 		return ret;
 
-	if ((strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) ||
-	    (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0)) {
+	if ((str_has_prefix(str, "onmatch(")) ||
+	    (str_has_prefix(str, "onmax("))) {
 		attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL);
 		if (!attrs->action_str[attrs->n_actions]) {
 			ret = -ENOMEM;
@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 {
 	int ret = 0;
 
-	if ((strncmp(str, "key=", sizeof("key=") - 1) = 0) ||
-	    (strncmp(str, "keys=", sizeof("keys=") - 1) = 0)) {
+	if ((str_has_prefix(str, "key=")) ||
+	    (str_has_prefix(str, "keys="))) {
 		attrs->keys_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->keys_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if ((strncmp(str, "val=", sizeof("val=") - 1) = 0) ||
-		 (strncmp(str, "vals=", sizeof("vals=") - 1) = 0) ||
-		 (strncmp(str, "values=", sizeof("values=") - 1) = 0)) {
+	} else if ((str_has_prefix(str, "val=")) ||
+		   (str_has_prefix(str, "vals=")) ||
+		   (str_has_prefix(str, "values="))) {
 		attrs->vals_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->vals_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "sort=", sizeof("sort=") - 1) = 0) {
+	} else if (str_has_prefix(str, "sort=")) {
 		attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->sort_key_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "name=", sizeof("name=") - 1) = 0) {
+	} else if (str_has_prefix(str, "name=")) {
 		attrs->name = kstrdup(str, GFP_KERNEL);
 		if (!attrs->name) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "clock=", sizeof("clock=") - 1) = 0) {
+	} else if (str_has_prefix(str, "clock=")) {
 		strsep(&str, "=");
 		if (!str) {
 			ret = -EINVAL;
@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "size=", sizeof("size=") - 1) = 0) {
+	} else if (str_has_prefix(str, "size=")) {
 		int map_bits = parse_map_size(str);
 
 		if (map_bits < 0) {
@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char *str)
 	if (!onmax_fn_name || !str)
 		goto free;
 
-	if (strncmp(onmax_fn_name, "save", sizeof("save") - 1) = 0) {
+	if (str_has_prefix(onmax_fn_name, "save")) {
 		char *params = strsep(&str, ")");
 
 		if (!params) {
@@ -4346,7 +4346,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) {
+		if (str_has_prefix(str, "onmatch(")) {
 			char *action_str = str + sizeof("onmatch(") - 1;
 
 			data = onmatch_parse(tr, action_str);
@@ -4355,7 +4355,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0) {
+		} else if (str_has_prefix(str, "onmax(")) {
 			char *action_str = str + sizeof("onmax(") - 1;
 
 			data = onmax_parse(action_str);
Signature · 1 line
2.19.2
author maintainer
#3 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

Quoted 11 lines · On Sat, 22 Dec 2018 11:20:09 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

This can be prone to bugs due to typos or bad cut and paste. Use the str_has_prefix() helper macro instead that removes the need for having two copies of the constant string.

Cc Tom Zanussi <[email protected]>

I have no idea why I copied your intel email. The linux.intel.com appears to be no longer active. I'm going to rebase to fix this email address.

-- Steve

Quoted 99 lines
---
 kernel/trace/trace_events_hist.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/trace/trace_events_hist.c +14 -14
index c5448c103770..9d590138f870 100644
@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs)
 	if (attrs->n_actions >= HIST_ACTIONS_MAX)
 		return ret;
 
-	if ((strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) ||
-	    (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0)) {
+	if ((str_has_prefix(str, "onmatch(")) ||
+	    (str_has_prefix(str, "onmax("))) {
 		attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL);
 		if (!attrs->action_str[attrs->n_actions]) {
 			ret = -ENOMEM;
@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 {
 	int ret = 0;
 
-	if ((strncmp(str, "key=", sizeof("key=") - 1) = 0) ||
-	    (strncmp(str, "keys=", sizeof("keys=") - 1) = 0)) {
+	if ((str_has_prefix(str, "key=")) ||
+	    (str_has_prefix(str, "keys="))) {
 		attrs->keys_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->keys_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if ((strncmp(str, "val=", sizeof("val=") - 1) = 0) ||
-		 (strncmp(str, "vals=", sizeof("vals=") - 1) = 0) ||
-		 (strncmp(str, "values=", sizeof("values=") - 1) = 0)) {
+	} else if ((str_has_prefix(str, "val=")) ||
+		   (str_has_prefix(str, "vals=")) ||
+		   (str_has_prefix(str, "values="))) {
 		attrs->vals_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->vals_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "sort=", sizeof("sort=") - 1) = 0) {
+	} else if (str_has_prefix(str, "sort=")) {
 		attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->sort_key_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "name=", sizeof("name=") - 1) = 0) {
+	} else if (str_has_prefix(str, "name=")) {
 		attrs->name = kstrdup(str, GFP_KERNEL);
 		if (!attrs->name) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "clock=", sizeof("clock=") - 1) = 0) {
+	} else if (str_has_prefix(str, "clock=")) {
 		strsep(&str, "=");
 		if (!str) {
 			ret = -EINVAL;
@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "size=", sizeof("size=") - 1) = 0) {
+	} else if (str_has_prefix(str, "size=")) {
 		int map_bits = parse_map_size(str);
 
 		if (map_bits < 0) {
@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char *str)
 	if (!onmax_fn_name || !str)
 		goto free;
 
-	if (strncmp(onmax_fn_name, "save", sizeof("save") - 1) = 0) {
+	if (str_has_prefix(onmax_fn_name, "save")) {
 		char *params = strsep(&str, ")");
 
 		if (!params) {
@@ -4346,7 +4346,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) {
+		if (str_has_prefix(str, "onmatch(")) {
 			char *action_str = str + sizeof("onmatch(") - 1;
 
 			data = onmatch_parse(tr, action_str);
@@ -4355,7 +4355,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0) {
+		} else if (str_has_prefix(str, "onmax(")) {
 			char *action_str = str + sizeof("onmax(") - 1;
 
 			data = onmax_parse(action_str);
author maintainer
#4 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

Quoted 5 lines · On Sat, 22 Dec 2018 13:01:07 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 1 line
Cc Tom Zanussi <[email protected]>

I have no idea why I copied your intel email. The linux.intel.com appears to be no longer active. I'm going to rebase to fix this email address.

Looking at the other patches, I guess I cut and pasted wrong.

I see: Tom Zanussi <[email protected]>

(with the "tom." part missing in this patch).

Still I'll fix it.

-- Steve

#5 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

In reply to Steven Rostedt

Hi Steve,

Quoted 16 lines · Steven Rostedt
Quoted 13 lines · On Sat, 22 Dec 2018 11:20:09 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

This can be prone to bugs due to typos or bad cut and paste. Use the
str_has_prefix() helper macro instead that removes the need for having two
copies of the constant string.

Quoted 5 lines
Quoted 1 line
Cc Tom Zanussi <[email protected]>

I have no idea why I copied your intel email. The linux.intel.com appears to be no longer active. I'm going to rebase to fix this email address.

linux.intel.com is active, but there's no zanussi there, just tom.zanussi ;-)

So [email protected] should work fine.

Tom

Quoted 126 lines

-- Steve

Quoted 120 lines
---
 kernel/trace/trace_events_hist.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/trace/trace_events_hist.c +0 -1
index c5448c103770..9d590138f870 100644
@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct
 hist_trigger_attrs *attrs)
 	if (attrs->n_actions >= HIST_ACTIONS_MAX)
 		return ret;
 
-	if ((strncmp(str, "onmatch(", sizeof("onmatch(") - 1) =

0) ||

kernel/trace/trace_events_hist.c +2 -1
-	    (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0)) {
+	if ((str_has_prefix(str, "onmatch(")) ||
+	    (str_has_prefix(str, "onmax("))) {
 		attrs->action_str[attrs->n_actions] = kstrdup(str,

GFP_KERNEL);

kernel/trace/trace_events_hist.c +2 -3
 		if (!attrs->action_str[attrs->n_actions]) {
 			ret = -ENOMEM;
@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str,
 struct hist_trigger_attrs *attrs)
 {
 	int ret = 0;
 
-	if ((strncmp(str, "key=", sizeof("key=") - 1) = 0) ||
-	    (strncmp(str, "keys=", sizeof("keys=") - 1) = 0)) {
+	if ((str_has_prefix(str, "key=")) ||
+	    (str_has_prefix(str, "keys="))) {
 		attrs->keys_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->keys_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if ((strncmp(str, "val=", sizeof("val=") - 1) = 0)

||

kernel/trace/trace_events_hist.c +0 -1
-		 (strncmp(str, "vals=", sizeof("vals=") - 1) = 0)

||

kernel/trace/trace_events_hist.c +0 -1
-		 (strncmp(str, "values=", sizeof("values=") - 1)

= 0)) {

kernel/trace/trace_events_hist.c +3 -1
+	} else if ((str_has_prefix(str, "val=")) ||
+		   (str_has_prefix(str, "vals=")) ||
+		   (str_has_prefix(str, "values="))) {
 		attrs->vals_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->vals_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "sort=", sizeof("sort=") - 1) =

0) {

kernel/trace/trace_events_hist.c +1 -1
+	} else if (str_has_prefix(str, "sort=")) {
 		attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->sort_key_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "name=", sizeof("name=") - 1) =

0) {

kernel/trace/trace_events_hist.c +1 -1
+	} else if (str_has_prefix(str, "name=")) {
 		attrs->name = kstrdup(str, GFP_KERNEL);
 		if (!attrs->name) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "clock=", sizeof("clock=") - 1) =

0) {

kernel/trace/trace_events_hist.c +2 -1
+	} else if (str_has_prefix(str, "clock=")) {
 		strsep(&str, "=");
 		if (!str) {
 			ret = -EINVAL;
@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct
 hist_trigger_attrs *attrs)
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "size=", sizeof("size=") - 1) =
 0) {
+	} else if (str_has_prefix(str, "size=")) {
 		int map_bits = parse_map_size(str);
kernel/trace/trace_events_hist.c +1 -1
 		if (map_bits < 0) {
@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char
 *str)
 	if (!onmax_fn_name || !str)
 		goto free;
 
-	if (strncmp(onmax_fn_name, "save", sizeof("save") - 1) =
 0) {
+	if (str_has_prefix(onmax_fn_name, "save")) {
 		char *params = strsep(&str, ")");
kernel/trace/trace_events_hist.c +1 -1
 		if (!params) {
@@ -4346,7 +4346,7 @@ static int parse_actions(struct
 hist_trigger_data *hist_data)
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (strncmp(str, "onmatch(", sizeof("onmatch(") -
 1) = 0) {
+		if (str_has_prefix(str, "onmatch(")) {
 			char *action_str = str +

sizeof("onmatch(") - 1;

kernel/trace/trace_events_hist.c +1 -3
 			data = onmatch_parse(tr, action_str);
@@ -4355,7 +4355,7 @@ static int parse_actions(struct
 hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (strncmp(str, "onmax(", sizeof("onmax(")
- 1) = 0) {
+		} else if (str_has_prefix(str, "onmax(")) {
 			char *action_str = str + sizeof("onmax(")
- 1;
 
 			data = onmax_parse(action_str);
author maintainer
#6 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

Quoted 21 lines · On Sat, 22 Dec 2018 12:03:41 -0600 Tom Zanussi <[email protected]> wrote:

Hi Steve,

Quoted 18 lines · Steven Rostedt
Quoted 14 lines · On Sat, 22 Dec 2018 11:20:09 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

This can be prone to bugs due to typos or bad cut and paste. Use the
str_has_prefix() helper macro instead that removes the need for having two
copies of the constant string.

Cc Tom Zanussi <[email protected]>
Quoted 8 lines
Quoted 3 lines

I have no idea why I copied your intel email. The linux.intel.com appears to be no longer active. I'm going to rebase to fix this email address.

linux.intel.com is active, but there's no zanussi there, just tom.zanussi ;-)

So [email protected] should work fine.

BTW, would you give me your ack-by?

-- Steve

Acked-by
#7 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

Quoted 30 lines · Steven Rostedt
Quoted 27 lines · On Sat, 22 Dec 2018 12:03:41 -0600 Tom Zanussi <[email protected]> wrote:

Hi Steve,

Quoted 23 lines · Steven Rostedt
Quoted 7 lines · On Sat, 22 Dec 2018 11:20:09 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

Quoted 8 lines

This can be prone to bugs due to typos or bad cut and paste. Use
the
str_has_prefix() helper macro instead that removes the need for having two
copies of the constant string.

Cc Tom Zanussi <[email protected]>

I have no idea why I copied your intel email. The linux.intel.com appears to be no longer active. I'm going to rebase to fix this email
address.

Quoted 7 lines
Quoted 4 lines

linux.intel.com is active, but there's no zanussi there, just tom.zanussi ;-)

So [email protected] should work fine.

BTW, would you give me your ack-by?

Sure,

Tom

Quoted 2 lines

-- Steve

#8 lore raw

Re: [for-next][PATCH 2/5] tracing: Use str_has_prefix() helper for histogram code

In reply to Steven Rostedt
Quoted 93 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The tracing histogram code contains a lot of instances of the construct:

strncmp(str, "const", sizeof("const") - 1)

This can be prone to bugs due to typos or bad cut and paste. Use the str_has_prefix() helper macro instead that removes the need for having two copies of the constant string.

---
 kernel/trace/trace_events_hist.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/trace/trace_events_hist.c +12 -12
index c5448c103770..9d590138f870 100644
@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs)
 	if (attrs->n_actions >= HIST_ACTIONS_MAX)
 		return ret;
 
-	if ((strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) ||
-	    (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0)) {
+	if ((str_has_prefix(str, "onmatch(")) ||
+	    (str_has_prefix(str, "onmax("))) {
 		attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL);
 		if (!attrs->action_str[attrs->n_actions]) {
 			ret = -ENOMEM;
@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 {
 	int ret = 0;
 
-	if ((strncmp(str, "key=", sizeof("key=") - 1) = 0) ||
-	    (strncmp(str, "keys=", sizeof("keys=") - 1) = 0)) {
+	if ((str_has_prefix(str, "key=")) ||
+	    (str_has_prefix(str, "keys="))) {
 		attrs->keys_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->keys_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if ((strncmp(str, "val=", sizeof("val=") - 1) = 0) ||
-		 (strncmp(str, "vals=", sizeof("vals=") - 1) = 0) ||
-		 (strncmp(str, "values=", sizeof("values=") - 1) = 0)) {
+	} else if ((str_has_prefix(str, "val=")) ||
+		   (str_has_prefix(str, "vals=")) ||
+		   (str_has_prefix(str, "values="))) {
 		attrs->vals_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->vals_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "sort=", sizeof("sort=") - 1) = 0) {
+	} else if (str_has_prefix(str, "sort=")) {
 		attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
 		if (!attrs->sort_key_str) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "name=", sizeof("name=") - 1) = 0) {
+	} else if (str_has_prefix(str, "name=")) {
 		attrs->name = kstrdup(str, GFP_KERNEL);
 		if (!attrs->name) {
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "clock=", sizeof("clock=") - 1) = 0) {
+	} else if (str_has_prefix(str, "clock=")) {
 		strsep(&str, "=");
 		if (!str) {
 			ret = -EINVAL;
@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
 			ret = -ENOMEM;
 			goto out;
 		}
-	} else if (strncmp(str, "size=", sizeof("size=") - 1) = 0) {
+	} else if (str_has_prefix(str, "size=")) {
 		int map_bits = parse_map_size(str);
 
 		if (map_bits < 0) {
@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char *str)
 	if (!onmax_fn_name || !str)
 		goto free;
 
-	if (strncmp(onmax_fn_name, "save", sizeof("save") - 1) = 0) {
+	if (str_has_prefix(onmax_fn_name, "save")) {
 		char *params = strsep(&str, ")");
 
 		if (!params) {

kernel/trace/trace_events_hist.c static int parse_actions(struct hist_trigger_data *hist_data) · line 4350

Quoted 6 lines
kernel/trace/trace_events_hist.c +1 -1
@@ -4346,7 +4346,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (strncmp(str, "onmatch(", sizeof("onmatch(") - 1) = 0) {
+		if (str_has_prefix(str, "onmatch(")) {
 			char *action_str = str + sizeof("onmatch(") - 1;

You'd better using the return value of str_has_prefix().

kernel/trace/trace_events_hist.c static int parse_actions(struct hist_trigger_data *hist_data) · line 4359

Quoted 9 lines
kernel/trace/trace_events_hist.c +1 -1
 			data = onmatch_parse(tr, action_str);
@@ -4355,7 +4355,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (strncmp(str, "onmax(", sizeof("onmax(") - 1) = 0) {
+		} else if (str_has_prefix(str, "onmax(")) {
 			char *action_str = str + sizeof("onmax(") - 1;

Ditto.

Thanks,
Namhyung

Quoted 6 lines
kernel/trace/trace_events_hist.c +0 -0
 			data = onmax_parse(action_str);
Signature · 1 line
2.19.2
author maintainer
#9 lore raw

PATCH 3/5 tracing: Use str_has_prefix() instead of using fixed sizes

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 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(-)
kernel/trace/trace.c +1 -1
index 5afcfecb4bc2..eac2824a18ab 100644
@@ -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;
 	}
kernel/trace/trace_events.c +1 -1
index bd0162c0467c..5b3b0c3c8a47 100644
@@ -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)
kernel/trace/trace_events_hist.c +1 -1
index 9d590138f870..0d878dcd1e4b 100644
@@ -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;
kernel/trace/trace_probe.c +2 -2
index ff86417c0149..541375737403 100644
@@ -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);
kernel/trace/trace_stack.c +1 -1
index e2a153fc1afc..3641f28c343f 100644
@@ -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;
Signature · 1 line
2.19.2
author maintainer
#10 lore raw

PATCH 4/5 tracing: Have the historgram use the result of str_has_prefix() for len of prefix

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

As str_has_prefix() returns the length on match, we can use that for the updating of the string pointer instead of recalculating the prefix size.

---
 kernel/trace/trace_events_hist.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/trace/trace_events_hist.c +5 -4
index 0d878dcd1e4b..449d90cfa151 100644
@@ -4342,12 +4342,13 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 	unsigned int i;
 	int ret = 0;
 	char *str;
+	int len;
 
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (str_has_prefix(str, "onmatch(")) {
-			char *action_str = str + sizeof("onmatch(") - 1;
+		if ((len = str_has_prefix(str, "onmatch("))) {
+			char *action_str = str + len;
 
 			data = onmatch_parse(tr, action_str);
 			if (IS_ERR(data)) {
@@ -4355,8 +4356,8 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (str_has_prefix(str, "onmax(")) {
-			char *action_str = str + sizeof("onmax(") - 1;
+		} else if ((len = str_has_prefix(str, "onmax("))) {
+			char *action_str = str + len;
 
 			data = onmax_parse(action_str);
 			if (IS_ERR(data)) {
Signature · 1 line
2.19.2
#11 lore raw

Re: [for-next][PATCH 4/5] tracing: Have the historgram use the result of str_has_prefix() for len of prefix

Quoted 18 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

As str_has_prefix() returns the length on match, we can use that for the updating of the string pointer instead of recalculating the prefix size.

---
 kernel/trace/trace_events_hist.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/trace/trace_events_hist.c +0 -0
index 0d878dcd1e4b..449d90cfa151 100644
@@ -4342,12 +4342,13 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 	unsigned int i;
 	int ret = 0;

kernel/trace/trace_events_hist.c static int parse_actions(struct hist_trigger_data *hist_data) · line 4351

Quoted 10 lines
kernel/trace/trace_events_hist.c +3 -2
 	char *str;
+	int len;
 
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (str_has_prefix(str, "onmatch(")) {
-			char *action_str = str + sizeof("onmatch(") - 1;
+		if ((len = str_has_prefix(str, "onmatch("))) {
+			char *action_str = str + len;

Ah you did it here.

Thanks,
Namhyung

Quoted 18 lines
kernel/trace/trace_events_hist.c +2 -2
 			data = onmatch_parse(tr, action_str);
 			if (IS_ERR(data)) {
@@ -4355,8 +4356,8 @@ static int parse_actions(struct hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (str_has_prefix(str, "onmax(")) {
-			char *action_str = str + sizeof("onmax(") - 1;
+		} else if ((len = str_has_prefix(str, "onmax("))) {
+			char *action_str = str + len;
 
 			data = onmax_parse(action_str);
 			if (IS_ERR(data)) {
Signature · 1 line
2.19.2
Acked-by on v1 4/5
#12 lore raw

Re: [for-next][PATCH 4/5] tracing: Have the historgram use the result of str_has_prefix() for len of prefix

In reply to Steven Rostedt

Hi Steve,

In the subject line, s/historgram/histogram...

Quoted 47 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

As str_has_prefix() returns the length on match, we can use that for the
updating of the string pointer instead of recalculating the prefix size.

---
 kernel/trace/trace_events_hist.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/trace/trace_events_hist.c +5 -5
index 0d878dcd1e4b..449d90cfa151 100644
@@ -4342,12 +4342,13 @@ static int parse_actions(struct
 hist_trigger_data *hist_data)
 	unsigned int i;
 	int ret = 0;
 	char *str;
+	int len;
 
 	for (i = 0; i < hist_data->attrs->n_actions; i++) {
 		str = hist_data->attrs->action_str[i];
 
-		if (str_has_prefix(str, "onmatch(")) {
-			char *action_str = str + sizeof("onmatch(")
- 1;
+		if ((len = str_has_prefix(str, "onmatch("))) {
+			char *action_str = str + len;
 
 			data = onmatch_parse(tr, action_str);
 			if (IS_ERR(data)) {
@@ -4355,8 +4356,8 @@ static int parse_actions(struct
 hist_trigger_data *hist_data)
 				break;
 			}
 			data->fn = action_trace;
-		} else if (str_has_prefix(str, "onmax(")) {
-			char *action_str = str + sizeof("onmax(") -
 1;
+		} else if ((len = str_has_prefix(str, "onmax("))) {
+			char *action_str = str + len;
 

kernel/trace/trace_events_hist.c static int parse_actions(struct hist_trigger_data *hist_data) · line 4363

Quoted 2 lines
kernel/trace/trace_events_hist.c +0 -0
 			data = onmax_parse(action_str);
 			if (IS_ERR(data)) {
author maintainer
#13 lore raw

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

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 kernel/trace/trace.c       |  8 +++++---
 kernel/trace/trace_probe.c | 17 +++++++++--------
 kernel/trace/trace_stack.c |  6 ++++--
 3 files changed, 18 insertions(+), 13 deletions(-)
kernel/trace/trace.c +5 -3
index eac2824a18ab..18b86c3974e1 100644
@@ -4408,13 +4408,15 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	int neg = 0;
 	int ret;
 	size_t orig_len = strlen(option);
+	int len;
 
 	cmp = strstrip(option);
 
-	if (str_has_prefix(cmp, "no")) {
+	len = str_has_prefix(cmp, "no");
+	if (len)
 		neg = 1;
-		cmp += 2;
-	}
+
+	cmp += len;
 
 	mutex_lock(&trace_types_lock);
 
kernel/trace/trace_probe.c +9 -8
index 541375737403..9962cb5da8ac 100644
@@ -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,
 			    struct fetch_insn *code, unsigned int flags)
 {
-	int ret = 0;
 	unsigned long param;
+	int ret = 0;
+	int len;
 
 	if (strcmp(arg, "retval") = 0) {
 		if (flags & TPARG_FL_RETURN)
 			code->op = FETCH_OP_RETVAL;
 		else
 			ret = -EINVAL;
-	} else if (str_has_prefix(arg, "stack")) {
-		if (arg[5] = '\0') {
+	} else if ((len = str_has_prefix(arg, "stack"))) {
+		if (arg[len] = '\0') {
 			code->op = FETCH_OP_STACKP;
-		} else if (isdigit(arg[5])) {
-			ret = kstrtoul(arg + 5, 10, &param);
+		} else if (isdigit(arg[len])) {
+			ret = kstrtoul(arg + len, 10, &param);
 			if (ret || ((flags & TPARG_FL_KERNEL) &&
 				    param > PARAM_MAX_STACK))
 				ret = -EINVAL;
@@ -213,10 +214,10 @@ 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)) &&
-		   str_has_prefix(arg, "arg")) {
-		if (!isdigit(arg[3]))
+		   (len = str_has_prefix(arg, "arg"))) {
+		if (!isdigit(arg[len]))
 			return -EINVAL;
-		ret = kstrtoul(arg + 3, 10, &param);
+		ret = kstrtoul(arg + len, 10, &param);
 		if (ret || !param || param > PARAM_MAX_STACK)
 			return -EINVAL;
 		code->op = FETCH_OP_ARG;
kernel/trace/trace_stack.c +4 -2
index 3641f28c343f..eec648a0d673 100644
@@ -448,8 +448,10 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
 
 static __init int enable_stacktrace(char *str)
 {
-	if (str_has_prefix(str, "_filter="))
-		strncpy(stack_trace_filter_buf, str+8, COMMAND_LINE_SIZE);
+	int len;
+
+	if ((len = str_has_prefix(str, "_filter=")))
+		strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
 
 	stack_tracer_enabled = 1;
 	last_stack_tracer_enabled = 1;
Signature · 1 line
2.19.2
maintainer Acked-by on v1 5/5
#14 lore raw

Re: [for-next][PATCH 5/5] tracing: Use the return of str_has_prefix() to remove open coded numbers

Quoted 8 lines · On Sat, 22 Dec 2018 11:20:12 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

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.

Looks good to me.

for trace_probe part.

Thanks!

Quoted 98 lines
---
 kernel/trace/trace.c       |  8 +++++---
 kernel/trace/trace_probe.c | 17 +++++++++--------
 kernel/trace/trace_stack.c |  6 ++++--
 3 files changed, 18 insertions(+), 13 deletions(-)
kernel/trace/trace.c +5 -3
index eac2824a18ab..18b86c3974e1 100644
@@ -4408,13 +4408,15 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	int neg = 0;
 	int ret;
 	size_t orig_len = strlen(option);
+	int len;
 
 	cmp = strstrip(option);
 
-	if (str_has_prefix(cmp, "no")) {
+	len = str_has_prefix(cmp, "no");
+	if (len)
 		neg = 1;
-		cmp += 2;
-	}
+
+	cmp += len;
 
 	mutex_lock(&trace_types_lock);
 
kernel/trace/trace_probe.c +9 -8
index 541375737403..9962cb5da8ac 100644
@@ -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,
 			    struct fetch_insn *code, unsigned int flags)
 {
-	int ret = 0;
 	unsigned long param;
+	int ret = 0;
+	int len;
 
 	if (strcmp(arg, "retval") = 0) {
 		if (flags & TPARG_FL_RETURN)
 			code->op = FETCH_OP_RETVAL;
 		else
 			ret = -EINVAL;
-	} else if (str_has_prefix(arg, "stack")) {
-		if (arg[5] = '\0') {
+	} else if ((len = str_has_prefix(arg, "stack"))) {
+		if (arg[len] = '\0') {
 			code->op = FETCH_OP_STACKP;
-		} else if (isdigit(arg[5])) {
-			ret = kstrtoul(arg + 5, 10, &param);
+		} else if (isdigit(arg[len])) {
+			ret = kstrtoul(arg + len, 10, &param);
 			if (ret || ((flags & TPARG_FL_KERNEL) &&
 				    param > PARAM_MAX_STACK))
 				ret = -EINVAL;
@@ -213,10 +214,10 @@ 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)) &&
-		   str_has_prefix(arg, "arg")) {
-		if (!isdigit(arg[3]))
+		   (len = str_has_prefix(arg, "arg"))) {
+		if (!isdigit(arg[len]))
 			return -EINVAL;
-		ret = kstrtoul(arg + 3, 10, &param);
+		ret = kstrtoul(arg + len, 10, &param);
 		if (ret || !param || param > PARAM_MAX_STACK)
 			return -EINVAL;
 		code->op = FETCH_OP_ARG;
kernel/trace/trace_stack.c +4 -2
index 3641f28c343f..eec648a0d673 100644
@@ -448,8 +448,10 @@ static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
 
 static __init int enable_stacktrace(char *str)
 {
-	if (str_has_prefix(str, "_filter="))
-		strncpy(stack_trace_filter_buf, str+8, COMMAND_LINE_SIZE);
+	int len;
+
+	if ((len = str_has_prefix(str, "_filter=")))
+		strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
 
 	stack_tracer_enabled = 1;
 	last_stack_tracer_enabled = 1;
Signature · 1 line
2.19.2
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#15 lore raw

Re: [for-next][PATCH 5/5] tracing: Use the return of str_has_prefix() to remove open coded numbers

Quoted 12 lines · On Sun, 23 Dec 2018 12:23:52 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 8 lines · On Sat, 22 Dec 2018 11:20:12 -0500 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

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.

Quoted 5 lines

Looks good to me.

for trace_probe part.

Thanks Masami!

-- Steve

author maintainer
#16 lore raw
In reply to Steven Rostedt
Quoted 21 lines · On Sat, 22 Dec 2018 11:20:07 -0500 Steven Rostedt <[email protected]> wrote:

They ran through all my tests, althought zero-day-bot had a weird build regression in sh, that looks totally unrelated:

Regressions in current branch:

arch/sh/kernel/dwarf.c:107:26: error: 'dwarf_frame_reg' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:1209:0: error: unterminated argument list invoking macro "WARN_ON" arch/sh/kernel/dwarf.c:226:12: error: 'dwarf_read_encoded_value' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:306:26: error: 'dwarf_lookup_cie' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:38:27: error: 'dwarf_frame_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:399:12: error: 'dwarf_cfa_execute_insns' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:41:27: error: 'dwarf_reg_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:580:22: error: unused variable 'frame' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:581:20: error: unused variable 'cie' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:582:20: error: unused variable 'fde' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:583:20: error: unused variable 'reg' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:584:16: error: unused variable 'addr' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:622:3: error: expected ';' at end of input arch/sh/kernel/dwarf.c:622:3: error: expected declaration or statement at end of input arch/sh/kernel/dwarf.c:622:3: error: 'WARN_ON' undeclared (first use in this function); did you mean 'WMARK_LOW'?

Quoted 2 lines

Pushing to my for-next branch should kick off another run. Let's see if it reports that again. Unless someone knows why that happened?

FYI,

Zeroday reported back a successful run of my for-next branch, and did it again, after I pushed a rebase that added an Acked-by. Thus, I'm guessing that the above is a simple fluke.

-- Steve

Acked-by on the v1 series
#17 lore raw
In reply to Steven Rostedt
Quoted 34 lines · Steven Rostedt

I hope everyone is OK with these changes. I pushed to linux-next but I'm willing to change them if there are still issues.

They ran through all my tests, althought zero-day-bot had a weird build regression in sh, that looks totally unrelated:

Regressions in current branch:

arch/sh/kernel/dwarf.c:107:26: error: 'dwarf_frame_reg' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:1209:0: error: unterminated argument list invoking macro "WARN_ON" arch/sh/kernel/dwarf.c:226:12: error: 'dwarf_read_encoded_value' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:306:26: error: 'dwarf_lookup_cie' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:38:27: error: 'dwarf_frame_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:399:12: error: 'dwarf_cfa_execute_insns' defined but not used [-Werror=unused-function] arch/sh/kernel/dwarf.c:41:27: error: 'dwarf_reg_cachep' defined but not used [-Werror=unused-variable] arch/sh/kernel/dwarf.c:580:22: error: unused variable 'frame' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:581:20: error: unused variable 'cie' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:582:20: error: unused variable 'fde' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:583:20: error: unused variable 'reg' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:584:16: error: unused variable 'addr' [-Werror=unused-variable] arch/sh/kernel/dwarf.c:622:3: error: expected ';' at end of input arch/sh/kernel/dwarf.c:622:3: error: expected declaration or statement at end of input arch/sh/kernel/dwarf.c:622:3: error: 'WARN_ON' undeclared (first use in this function); did you mean 'WMARK_LOW'?

Pushing to my for-next branch should kick off another run. Let's see if it reports that again. Unless someone knows why that happened?

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next

Head SHA1: 92b9de3e574bd874188a4e27a8830bb901a08ef8

Quoted 6 lines

Steven Rostedt (VMware) (5):
string.h: Add str_has_prefix() helper function
tracing: Use str_has_prefix() helper for histogram code
tracing: Use str_has_prefix() instead of using fixed sizes
tracing: Have the historgram use the result of str_has_prefix() for len of prefix
tracing: Use the return of str_has_prefix() to remove open coded numbers

For the series:

Thanks,
Namhyung

Quoted 9 lines

----

 include/linux/string.h           | 20 ++++++++++++++++++++
 kernel/trace/trace.c             |  8 +++++---
 kernel/trace/trace_events.c      |  2 +-
 kernel/trace/trace_events_hist.c | 35 ++++++++++++++++++-----------------
 kernel/trace/trace_probe.c       | 17 +++++++++--------
 kernel/trace/trace_stack.c       |  6 ++++--
 6 files changed, 57 insertions(+), 31 deletions(-)
author maintainer
#18 lore raw
Quoted 10 lines · On Sun, 23 Dec 2018 12:41:20 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 6 lines

Steven Rostedt (VMware) (5):
string.h: Add str_has_prefix() helper function
tracing: Use str_has_prefix() helper for histogram code
tracing: Use str_has_prefix() instead of using fixed sizes
tracing: Have the historgram use the result of str_has_prefix() for len of prefix
tracing: Use the return of str_has_prefix() to remove open coded numbers

For the series:

Thanks Namhyung!

-- Steve