From patchwork Wed Sep 23 01:57:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 54024 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id D019F22B1E for ; Wed, 23 Sep 2015 02:11:44 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf16835518wic.1 for ; Tue, 22 Sep 2015 19:11:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=M5bDuH5iirOt0eSuoXQqTLpp0p3gdEGwyszaWpfVFxE=; b=MMA6nf2d9NNRuWMD+IHG94pE5jMyk8nWI5sghTwDOsWI61XkSzqJN8ZisxfNcE+79/ 3hvU1Dk2/yqZkpz6DDFxZdHlb1WBM8O1M4biOJ277Of6h8mUEGlEOntwwbvHTYx1/vcQ D219qp8HH2ystjdoasps1rUCbmZUCc0qIuhxYPjTlvqEkoqc9LmwAEuWgD4zHvwMQY+M yysp//pf1rWCVyLEl6TX8uDIrrNUZBoSQZZ/ygZoSib8fcR/COCmMzNw3pV6mVtAVcFw 5S2gfVV2NWAKmKzW2hUtKIaV0ZLAW3lIs9TjNricnV+G+Loy087/FYVjOvx2MxW/hV1w LTYg== X-Gm-Message-State: ALoCoQm+0iaEgomXjR0TySkdB70hWMIUYjYTFaooklyp9pP7SfFPNXamPtV9J7ML2RSKz+5HAZUL X-Received: by 10.112.55.69 with SMTP id q5mr4765877lbp.24.1442974304137; Tue, 22 Sep 2015 19:11:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.164 with SMTP id s4ls17005laa.63.gmail; Tue, 22 Sep 2015 19:11:43 -0700 (PDT) X-Received: by 10.112.162.34 with SMTP id xx2mr5016409lbb.109.1442974303970; Tue, 22 Sep 2015 19:11:43 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id h127si1729853lfg.121.2015.09.22.19.11.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 19:11:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lahg1 with SMTP id g1so34384632lah.1 for ; Tue, 22 Sep 2015 19:11:43 -0700 (PDT) X-Received: by 10.152.18.167 with SMTP id x7mr148545lad.29.1442974303823; Tue, 22 Sep 2015 19:11:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp818618lbq; Tue, 22 Sep 2015 19:11:42 -0700 (PDT) X-Received: by 10.69.12.162 with SMTP id er2mr35053544pbd.24.1442974302733; Tue, 22 Sep 2015 19:11:42 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fc1si6791774pab.196.2015.09.22.19.11.42; Tue, 22 Sep 2015 19:11:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935209AbbIWCLh (ORCPT + 30 others); Tue, 22 Sep 2015 22:11:37 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:33199 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935192AbbIWCLe (ORCPT ); Tue, 22 Sep 2015 22:11:34 -0400 Received: from [179.235.152.40] (helo=zoo.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZeZVQ-0002Ae-2x; Wed, 23 Sep 2015 02:10:00 +0000 Received: by zoo.infradead.org (Postfix, from userid 1000) id C485322015F; Tue, 22 Sep 2015 22:58:03 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Wang Nan , Alexei Starovoitov , Brendan Gregg , Daniel Borkmann , David Ahern , He Kuang , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 2/9] perf tools: Don't assume that the parser returns non empty evsel list Date: Tue, 22 Sep 2015 22:57:55 -0300 Message-Id: <1442973482-11945-3-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1442973482-11945-1-git-send-email-acme@kernel.org> References: <1442973482-11945-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: acme@kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Wang Nan 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 Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li 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 --- 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);