tracing: Use str_has_prefix() helper for histogram code

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 <tom.zanussi@linux.intel.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 72921427
...@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs) ...@@ -1881,8 +1881,8 @@ static int parse_action(char *str, struct hist_trigger_attrs *attrs)
if (attrs->n_actions >= HIST_ACTIONS_MAX) if (attrs->n_actions >= HIST_ACTIONS_MAX)
return ret; return ret;
if ((strncmp(str, "onmatch(", sizeof("onmatch(") - 1) == 0) || if ((str_has_prefix(str, "onmatch(")) ||
(strncmp(str, "onmax(", sizeof("onmax(") - 1) == 0)) { (str_has_prefix(str, "onmax("))) {
attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL); attrs->action_str[attrs->n_actions] = kstrdup(str, GFP_KERNEL);
if (!attrs->action_str[attrs->n_actions]) { if (!attrs->action_str[attrs->n_actions]) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs) ...@@ -1899,34 +1899,34 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
{ {
int ret = 0; int ret = 0;
if ((strncmp(str, "key=", sizeof("key=") - 1) == 0) || if ((str_has_prefix(str, "key=")) ||
(strncmp(str, "keys=", sizeof("keys=") - 1) == 0)) { (str_has_prefix(str, "keys="))) {
attrs->keys_str = kstrdup(str, GFP_KERNEL); attrs->keys_str = kstrdup(str, GFP_KERNEL);
if (!attrs->keys_str) { if (!attrs->keys_str) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
} else if ((strncmp(str, "val=", sizeof("val=") - 1) == 0) || } else if ((str_has_prefix(str, "val=")) ||
(strncmp(str, "vals=", sizeof("vals=") - 1) == 0) || (str_has_prefix(str, "vals=")) ||
(strncmp(str, "values=", sizeof("values=") - 1) == 0)) { (str_has_prefix(str, "values="))) {
attrs->vals_str = kstrdup(str, GFP_KERNEL); attrs->vals_str = kstrdup(str, GFP_KERNEL);
if (!attrs->vals_str) { if (!attrs->vals_str) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; 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); attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
if (!attrs->sort_key_str) { if (!attrs->sort_key_str) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
} else if (strncmp(str, "name=", sizeof("name=") - 1) == 0) { } else if (str_has_prefix(str, "name=")) {
attrs->name = kstrdup(str, GFP_KERNEL); attrs->name = kstrdup(str, GFP_KERNEL);
if (!attrs->name) { if (!attrs->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
} else if (strncmp(str, "clock=", sizeof("clock=") - 1) == 0) { } else if (str_has_prefix(str, "clock=")) {
strsep(&str, "="); strsep(&str, "=");
if (!str) { if (!str) {
ret = -EINVAL; ret = -EINVAL;
...@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs) ...@@ -1939,7 +1939,7 @@ static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
ret = -ENOMEM; ret = -ENOMEM;
goto out; 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); int map_bits = parse_map_size(str);
if (map_bits < 0) { if (map_bits < 0) {
...@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char *str) ...@@ -3558,7 +3558,7 @@ static struct action_data *onmax_parse(char *str)
if (!onmax_fn_name || !str) if (!onmax_fn_name || !str)
goto free; goto free;
if (strncmp(onmax_fn_name, "save", sizeof("save") - 1) == 0) { if (str_has_prefix(onmax_fn_name, "save")) {
char *params = strsep(&str, ")"); char *params = strsep(&str, ")");
if (!params) { if (!params) {
...@@ -4346,7 +4346,7 @@ static int parse_actions(struct hist_trigger_data *hist_data) ...@@ -4346,7 +4346,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
for (i = 0; i < hist_data->attrs->n_actions; i++) { for (i = 0; i < hist_data->attrs->n_actions; i++) {
str = hist_data->attrs->action_str[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; char *action_str = str + sizeof("onmatch(") - 1;
data = onmatch_parse(tr, action_str); data = onmatch_parse(tr, action_str);
...@@ -4355,7 +4355,7 @@ static int parse_actions(struct hist_trigger_data *hist_data) ...@@ -4355,7 +4355,7 @@ static int parse_actions(struct hist_trigger_data *hist_data)
break; break;
} }
data->fn = action_trace; 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; char *action_str = str + sizeof("onmax(") - 1;
data = onmax_parse(action_str); data = onmax_parse(action_str);
......
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