diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-04-22 15:10:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-04-29 09:37:59 -0400 |
commit | c056ba6a174f4d5d79fe27f259fc133041a451da (patch) | |
tree | 28daffe503887d3a97c65f2fd9b543bf3617ee77 /tools/perf/util/parse-events.c | |
parent | 6297d42372b6ff02135ce170b0d90ccf0b1531e4 (diff) |
perf tools: Always bail out when config_attr function fails
Not sure why we allowed the fail state, but it's wrong. Wrong type for
'name' term can cause segfault, and there's probably more fun hidden.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6978cc377957..1e42f2ceec3d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -549,6 +549,12 @@ do { \ | |||
549 | } while (0) | 549 | } while (0) |
550 | 550 | ||
551 | switch (term->type_term) { | 551 | switch (term->type_term) { |
552 | case PARSE_EVENTS__TERM_TYPE_USER: | ||
553 | /* | ||
554 | * Always succeed for sysfs terms, as we dont know | ||
555 | * at this point what type they need to have. | ||
556 | */ | ||
557 | return 0; | ||
552 | case PARSE_EVENTS__TERM_TYPE_CONFIG: | 558 | case PARSE_EVENTS__TERM_TYPE_CONFIG: |
553 | CHECK_TYPE_VAL(NUM); | 559 | CHECK_TYPE_VAL(NUM); |
554 | attr->config = term->val.num; | 560 | attr->config = term->val.num; |
@@ -583,12 +589,12 @@ do { \ | |||
583 | } | 589 | } |
584 | 590 | ||
585 | static int config_attr(struct perf_event_attr *attr, | 591 | static int config_attr(struct perf_event_attr *attr, |
586 | struct list_head *head, int fail) | 592 | struct list_head *head) |
587 | { | 593 | { |
588 | struct parse_events_term *term; | 594 | struct parse_events_term *term; |
589 | 595 | ||
590 | list_for_each_entry(term, head, list) | 596 | list_for_each_entry(term, head, list) |
591 | if (config_term(attr, term) && fail) | 597 | if (config_term(attr, term)) |
592 | return -EINVAL; | 598 | return -EINVAL; |
593 | 599 | ||
594 | return 0; | 600 | return 0; |
@@ -605,7 +611,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, | |||
605 | attr.config = config; | 611 | attr.config = config; |
606 | 612 | ||
607 | if (head_config && | 613 | if (head_config && |
608 | config_attr(&attr, head_config, 1)) | 614 | config_attr(&attr, head_config)) |
609 | return -EINVAL; | 615 | return -EINVAL; |
610 | 616 | ||
611 | return add_event(list, idx, &attr, NULL); | 617 | return add_event(list, idx, &attr, NULL); |
@@ -659,7 +665,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx, | |||
659 | * Configure hardcoded terms first, no need to check | 665 | * Configure hardcoded terms first, no need to check |
660 | * return value when called with fail == 0 ;) | 666 | * return value when called with fail == 0 ;) |
661 | */ | 667 | */ |
662 | config_attr(&attr, head_config, 0); | 668 | if (config_attr(&attr, head_config)) |
669 | return -EINVAL; | ||
663 | 670 | ||
664 | if (perf_pmu__config(pmu, &attr, head_config)) | 671 | if (perf_pmu__config(pmu, &attr, head_config)) |
665 | return -EINVAL; | 672 | return -EINVAL; |