From patchwork Mon Sep 21 21:23:15 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: 53988 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 1542922B04 for ; Mon, 21 Sep 2015 21:24:22 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf35867985wic.3 for ; Mon, 21 Sep 2015 14:24:21 -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=bl0xu3qE7gg7sq3/drCuChcG/QSnNrBit7J+R9//qqnwuG1KWWj85/xtlaAlgnBe07 JGyX+FyUsFZPmbUqfiTFhVc0P4emPsIHxg9tHFz5iGGQHdBr8j0KtcGTQZKF86DCldrV Qeunlwg/N+vfF7SXl41oAa+9gF0L3+wA+JfuY96Ej4pFmU1fOUDLpev7pV+zFpG3Swsf jphSSF+fojvBa5PCoJdEG8t0Hq31SrfCLK/No21q2SEl5hQx34BH8g1rrzlev6VVpXuz /B6IjvGQOcSq/338OtCyYOrlGznnAl1IMerE5tryohyjPEB7hBKGZ7VsPLGNkJK0/Jdp JujA== X-Gm-Message-State: ALoCoQmc9fdetBAu5UDwsyXCG8whm1kvyRqiszyvJyZtK7RV5kkaEyNKJb/zWsnzAPW8U3NPtW4E X-Received: by 10.112.130.41 with SMTP id ob9mr3581728lbb.17.1442870661380; Mon, 21 Sep 2015 14:24:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.225 with SMTP id u1ls528499laa.83.gmail; Mon, 21 Sep 2015 14:24:21 -0700 (PDT) X-Received: by 10.112.159.35 with SMTP id wz3mr8432096lbb.13.1442870661184; Mon, 21 Sep 2015 14:24:21 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id qo1si17264917lbb.135.2015.09.21.14.24.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Sep 2015 14:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbpo4 with SMTP id o4so58393491lbp.2 for ; Mon, 21 Sep 2015 14:24:21 -0700 (PDT) X-Received: by 10.152.161.232 with SMTP id xv8mr8626364lab.32.1442870661029; Mon, 21 Sep 2015 14:24:21 -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 w3csp105408lbq; Mon, 21 Sep 2015 14:24:19 -0700 (PDT) X-Received: by 10.68.68.134 with SMTP id w6mr27516959pbt.61.1442870659733; Mon, 21 Sep 2015 14:24:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cc1si40586416pad.49.2015.09.21.14.24.19; Mon, 21 Sep 2015 14:24:19 -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 S1756760AbbIUVX5 (ORCPT + 30 others); Mon, 21 Sep 2015 17:23:57 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:39525 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932467AbbIUVXv (ORCPT ); Mon, 21 Sep 2015 17:23:51 -0400 Received: from [2804:14d:1285:110c:213:3bff:fe74:11bc] (helo=zoo.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze8YZ-0007fF-Hn; Mon, 21 Sep 2015 21:23:27 +0000 Received: by zoo.infradead.org (Postfix, from userid 1000) id 79BCE22015E; Mon, 21 Sep 2015 18:23:23 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Wang Nan , Alexei Starovoitov , Brendan Gregg , Daniel Borkmann , David Ahern , He Kuang , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Zefan Li , pi3orama@163.com, Arnaldo Carvalho de Melo Subject: [PATCH 2/8] perf tools: Don't assume that the parser returns non empty evsel list Date: Mon, 21 Sep 2015 18:23:15 -0300 Message-Id: <1442870601-26004-3-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1442870601-26004-1-git-send-email-acme@kernel.org> References: <1442870601-26004-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.217.169 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);