Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1219761
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 01/27] perf tools: Don't write to evsel if parser doesn't collect evsel |
| Date | 2015-09-06 09:20 +0200 |
| Message-ID | <q5Cp5-gk-45@gated-at.bofh.it> (permalink) |
| References | <q5Cp3-gk-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
If parse_events__scanner() collects no entry, perf_evlist__last(evlist)
is invalid.
Although it shouldn't happen at this point, before calling
perf_evlist__last(), we should ensure the list is not empty for safety
reason.
There are 3 places need this checking:
1. Before setting cmdline_group_boundary;
2. Before __perf_evlist__set_leader();
3. In foreach_evsel_in_last_glob.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: https://lkml.kernel.org/n/1441176553-116129-1-git-send-email-wangnan0@huawei.com
[wangnan: Enforce the assumption that parser never collect empty list]
---
tools/perf/util/parse-events.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 3840176..07ce501 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -793,6 +793,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;
@@ -1143,10 +1148,16 @@ int parse_events(struct perf_evlist *evlist, const char *str,
int entries = data.idx - evlist->nr_entries;
struct perf_evsel *last;
+ if (list_empty(&data.list)) {
+ WARN_ONCE(true, "WARNING: event parser found nothing");
+ return -1;
+ }
+
+ last = list_entry(data.list.prev, struct perf_evsel, node);
+ last->cmdline_group_boundary = true;
+
perf_evlist__splice_list_tail(evlist, &data.list, entries);
evlist->nr_groups += data.nr_groups;
- last = perf_evlist__last(evlist);
- last->cmdline_group_boundary = true;
return 0;
}
@@ -1252,7 +1263,13 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist,
struct perf_evsel *last = NULL;
int err;
- if (evlist->nr_entries > 0)
+ /*
+ * 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 (!list_empty(&evlist->entries))
last = perf_evlist__last(evlist);
do {
--
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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/27] perf tools: filtering events using eBPF programs Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 07/27] perf record: Load all eBPF object into kernel Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 22/27] perf tools: Use same BPF program if arguments are identical Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 20/27] perf tools: Add prologue for BPF programs for fetching arguments Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 17/27] perf probe: Reset args and nargs for probe_trace_event when failure Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 01/27] perf tools: Don't write to evsel if parser doesn't collect evsel Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 13/27] perf tools: Compile scriptlets to BPF objects when passing '.c' to --event Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 06/27] perf bpf: Collect 'struct perf_probe_event' for bpf_program Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 23/27] perf record: Support custom vmlinux path Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[PATCH 18/27] perf tools: Add BPF_PROLOGUE config options for further patches Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:20 +0200
[tip:perf/core] perf tools: regs_query_register_offset() infrastructure tip-bot for Wang Nan <tipbot@zytor.com> - 2015-09-16 09:40 +0200
[PATCH 11/27] perf tools: Sync setting of real bpf events with placeholder Wang Nan <wangnan0@huawei.com> - 2015-09-06 09:30 +0200
csiph-web