Skip to contentSkip to conversation

perf symbols: No need to check if sym->name is NULL

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Feb 14, 2017 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  a7c3899c06865c75f8887f33d9043f6e8e780e71
Gitweb:     http://git.kernel.org/tip/a7c3899c06865c75f8887f33d9043f6e8e780e71
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Mon, 13 Feb 2017 16:52:15 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 13 Feb 2017 17:22:34 -0300

perf symbols: No need to check if sym->name is NULL

As it is an array, so will always evaluate to 'true', as reported by clang:

builtin-sched.c:2070:19: error: address of array 'sym->name' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]

                  if (sym && sym->name) {
                          ~~ ~~~~~^~~~

1 warning generated.

So just ditch all those useless checks.

---
 tools/perf/builtin-kmem.c        | 4 ++--
 tools/perf/builtin-sched.c       | 2 +-
 tools/perf/util/evsel_fprintf.c  | 1 -
 tools/perf/util/machine.c        | 2 +-
 tools/perf/util/symbol_fprintf.c | 2 +-
 5 files changed, 5 insertions(+), 6 deletions(-)
tools/perf/builtin-kmem.c +2 -2
index 29f4751..6da8d08 100644
@@ -1065,7 +1065,7 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 
 		data = rb_entry(next, struct page_stat, node);
 		sym = machine__find_kernel_function(machine, data->callsite, &map);
-		if (sym && sym->name)
+		if (sym)
 			caller = sym->name;
 		else
 			scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite);
@@ -1107,7 +1107,7 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 
 		data = rb_entry(next, struct page_stat, node);
 		sym = machine__find_kernel_function(machine, data->callsite, &map);
-		if (sym && sym->name)
+		if (sym)
 			caller = sym->name;
 		else
 			scnprintf(buf, sizeof(buf), "%"PRIx64, data->callsite);
tools/perf/builtin-sched.c +1 -1
index daceb32..270eb2d 100644
@@ -2067,7 +2067,7 @@ static void save_task_callchain(struct perf_sched *sched,
 			break;
 
 		sym = node->sym;
-		if (sym && sym->name) {
+		if (sym) {
 			if (!strcmp(sym->name, "schedule") ||
 			    !strcmp(sym->name, "__schedule") ||
 			    !strcmp(sym->name, "preempt_schedule"))
tools/perf/util/evsel_fprintf.c +0 -1
index 6b29255..4ef5184 100644
@@ -168,7 +168,6 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
 
 			if (symbol_conf.bt_stop_list &&
 			    node->sym &&
-			    node->sym->name &&
 			    strlist__has_entry(symbol_conf.bt_stop_list,
 					       node->sym->name)) {
 				break;
tools/perf/util/machine.c +1 -1
index 747a034..a1043cf 100644
@@ -1565,7 +1565,7 @@ int machine__process_event(struct machine *machine, union perf_event *event,
 
 static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
 {
-	if (sym->name && !regexec(regex, sym->name, 0, NULL, 0))
+	if (!regexec(regex, sym->name, 0, NULL, 0))
 		return 1;
 	return 0;
 }
tools/perf/util/symbol_fprintf.c +1 -1
index 7c6b33e..63694e1 100644
@@ -21,7 +21,7 @@ size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
 	unsigned long offset;
 	size_t length;
 
-	if (sym && sym->name) {
+	if (sym) {
 		length = fprintf(fp, "%s", sym->name);
 		if (al && print_offsets) {
 			if (al->addr < sym->end)