Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1231107

[PATCH 2/9] perf tools: Don't assume that the parser returns non empty evsel list

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 2/9] perf tools: Don't assume that the parser returns non empty evsel list
Date 2015-09-23 04:20 +0200
Message-ID <qbHP3-7ct-15@gated-at.bofh.it> (permalink)
References <qbHP3-7ct-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Wang Nan <wangnan0@huawei.com>

Don't blindly retrieve and use a last element in the lists returned by
parse_events__scanner(), as it may have collected no entries, i.e.
return an empty list.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1441523623-152703-2-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-events.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 0fde5293a38e..61c2bc20926d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -827,6 +827,11 @@ void parse_events__set_leader(char *name, struct list_head *list)
 {
 	struct perf_evsel *leader;
 
+	if (list_empty(list)) {
+		WARN_ONCE(true, "WARNING: failed to set leader: empty list");
+		return;
+	}
+
 	__perf_evlist__set_leader(list);
 	leader = list_entry(list->next, struct perf_evsel, node);
 	leader->group_name = name ? strdup(name) : NULL;
@@ -1176,6 +1181,11 @@ int parse_events(struct perf_evlist *evlist, const char *str,
 	if (!ret) {
 		struct perf_evsel *last;
 
+		if (list_empty(&data.list)) {
+			WARN_ONCE(true, "WARNING: event parser found nothing");
+			return -1;
+		}
+
 		perf_evlist__splice_list_tail(evlist, &data.list);
 		evlist->nr_groups += data.nr_groups;
 		last = perf_evlist__last(evlist);
@@ -1285,6 +1295,12 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist,
 	struct perf_evsel *last = NULL;
 	int err;
 
+	/*
+	 * Don't return when list_empty, give func a chance to report
+	 * error when it found last == NULL.
+	 *
+	 * So no need to WARN here, let *func do this.
+	 */
 	if (evlist->nr_entries > 0)
 		last = perf_evlist__last(evlist);
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 0/9] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 6/9] tools lib bpf: Use FEATURE_USER to allow building in the same dir as perf Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 4/9] tools lib bpf: Fix up FEATURE_{TESTS,DISPLAY} usage Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 1/9] perf probe: Fix a segfault when removing uprobe events Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 8/9] tools vm: Fix build due to removal of tools/lib/api/fs/debugfs.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 7/9] perf tools: Add include/err.h into MANIFEST Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 3/9] tools build: Fixup feature detection display function name Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 2/9] perf tools: Don't assume that the parser returns non empty evsel list Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  [PATCH 9/9] perf record: Synthesize COMM event for a command line workload Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-23 04:20 +0200
  Re: [GIT PULL 0/9] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2015-09-23 09:50 +0200

csiph-web