From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756906AbbEFDFG (ORCPT ); Tue, 5 May 2015 23:05:06 -0400 Received: from terminus.zytor.com ([198.137.202.10]:35884 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752956AbbEFDE7 (ORCPT ); Tue, 5 May 2015 23:04:59 -0400 Date: Tue, 5 May 2015 20:04:44 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: tglx@linutronix.de, paulus@samba.org, dsahern@gmail.com, a.p.zijlstra@chello.nl, jolsa@kernel.org, namhyung@kernel.org, mingo@kernel.org, hpa@zytor.com, acme@redhat.com, linux-kernel@vger.kernel.org Reply-To: jolsa@kernel.org, a.p.zijlstra@chello.nl, dsahern@gmail.com, paulus@samba.org, tglx@linutronix.de, acme@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, namhyung@kernel.org In-Reply-To: <1429729824-13932-4-git-send-email-jolsa@kernel.org> References: <1429729824-13932-4-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Always bail out when config_attr function fails Git-Commit-ID: c056ba6a174f4d5d79fe27f259fc133041a451da X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: c056ba6a174f4d5d79fe27f259fc133041a451da Gitweb: http://git.kernel.org/tip/c056ba6a174f4d5d79fe27f259fc133041a451da Author: Jiri Olsa AuthorDate: Wed, 22 Apr 2015 21:10:18 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 29 Apr 2015 10:37:59 -0300 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 Cc: David Ahern Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1429729824-13932-4-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6978cc3..1e42f2c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -549,6 +549,12 @@ do { \ } while (0) switch (term->type_term) { + case PARSE_EVENTS__TERM_TYPE_USER: + /* + * Always succeed for sysfs terms, as we dont know + * at this point what type they need to have. + */ + return 0; case PARSE_EVENTS__TERM_TYPE_CONFIG: CHECK_TYPE_VAL(NUM); attr->config = term->val.num; @@ -583,12 +589,12 @@ do { \ } static int config_attr(struct perf_event_attr *attr, - struct list_head *head, int fail) + struct list_head *head) { struct parse_events_term *term; list_for_each_entry(term, head, list) - if (config_term(attr, term) && fail) + if (config_term(attr, term)) return -EINVAL; return 0; @@ -605,7 +611,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config; if (head_config && - config_attr(&attr, head_config, 1)) + config_attr(&attr, head_config)) return -EINVAL; return add_event(list, idx, &attr, NULL); @@ -659,7 +665,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx, * Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ - config_attr(&attr, head_config, 0); + if (config_attr(&attr, head_config)) + return -EINVAL; if (perf_pmu__config(pmu, &attr, head_config)) return -EINVAL;