perf tools: Don't set cmdline_group_boundary if no evsel is collected
PATCH 1/1 perf tools: Don't set cmdline_group_boundary if no evsel is collected
If parse_events__scanner() collects no entry, perf_evlist__last(evlist) is invalid. Then setting of cmdline_group_boundary touches invalid.
It could happend in currect BPF implementation. See [1]. Although it can be fixed, for safety reason it whould be better to introduce this check.
[1]: http://lkml.kernel.org/n/[email protected]
--- tools/perf/util/parse-events.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/parse-events.c +4 -2
@@ -1171,9 +1171,11 @@ int parse_events(struct perf_evlist *evlist, const char *str,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; +if (entries >0 ) { + last =perf_evlist__last (evlist); + last->cmdline_group_boundary = true; + }return 0 ; }
Signature · 1 line
1.8.3.4
Quoted 25 lines · Wang Nan
If
parse_events__scanner()collects no entry,perf_evlist__last(evlist)is invalid. Then setting ofcmdline_group_boundarytouches invalid.It could happend in currect BPF implementation. See [1]. Although it can be fixed, for safety reason it whould be better to introduce this check.
[1]: http://lkml.kernel.org/n/[email protected]
Signed-off-by Wang Nan <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Namhyung Kim <[email protected]>Cc Zefan Li <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/parse-events.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/perf/util/parse-events.c +0
-0
tools/perf/util/parse-events.c int parse_events(struct perf_evlist *evlist, const char *str, · line 1175
Quoted 7 lines
tools/perf/util/parse-events.c +1
-2@@ -1171,9 +1171,11 @@ int parse_events(struct perf_evlist *evlist, const char *str,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; +if (entries >0 ) {
Now I think chinking this before list splice should be better. Plase ignore this patch.
Thank you.
Quoted 6 lines
tools/perf/util/parse-events.c +3
-0+ last =perf_evlist__last (evlist); + last->cmdline_group_boundary = true; + }return 0 ; }