From patchwork Sun Sep 6 07:13:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53174 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 35ED022B05 for ; Sun, 6 Sep 2015 07:16:00 +0000 (UTC) Received: by lbcjc2 with SMTP id jc2sf17267979lbc.0 for ; Sun, 06 Sep 2015 00:15:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=0GOadF9Is5xR8t0onHor6ttnLP0vaBQoSc6A8OaG4gc=; b=HZJZI1C5nkYU/ZYeP5EDjhH6RFCgGhmj5DdBKI+WMB/BSeLSDNbe2YuVQldB7g/ili tpsFHJwM6sOswF4cnYvpFe2VvKISsW6gi+Y1ltYyqDFrRvz+uMY4++GbHj0O97DKLGyc 9mAGAclwRB1KzWERI8coH8AfsK2ZuGqoXNuk2xT9mOZeU1+gqwZpcmcKnD4CvOl+CIn8 +I+fB2Rj9TJpMvaoljjLRFMNeTTTJoQSm2+Vq0FMnrV0TEyKlR9SfUOvUgbZ0RS55s5v LMzQd11o/fDnmxL7wZPOWFGnEFUurIZnxfShRHughoCPlq76hVW0KsDTuZ9lKLmOcfgK gT6w== X-Gm-Message-State: ALoCoQmHxtVRb+URxUNMgPPGpLLIAyibEXU+hs+gsA1fy2lO1UL4Fs6gIPf+NBC/SoS5BS6Uf3gc X-Received: by 10.112.78.101 with SMTP id a5mr3388484lbx.9.1441523759067; Sun, 06 Sep 2015 00:15:59 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.6 with SMTP id m6ls563355laj.32.gmail; Sun, 06 Sep 2015 00:15:58 -0700 (PDT) X-Received: by 10.152.44.196 with SMTP id g4mr11887733lam.56.1441523758748; Sun, 06 Sep 2015 00:15:58 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id an10si7219387lbc.116.2015.09.06.00.15.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 00:15:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbcjc2 with SMTP id jc2so26935646lbc.0 for ; Sun, 06 Sep 2015 00:15:58 -0700 (PDT) X-Received: by 10.152.21.196 with SMTP id x4mr11528332lae.117.1441523758628; Sun, 06 Sep 2015 00:15:58 -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.164.42 with SMTP id yn10csp843660lbb; Sun, 6 Sep 2015 00:15:57 -0700 (PDT) X-Received: by 10.68.104.227 with SMTP id gh3mr30725757pbb.108.1441523754137; Sun, 06 Sep 2015 00:15:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yr4si13732023pbc.140.2015.09.06.00.15.53; Sun, 06 Sep 2015 00:15:54 -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 S1752396AbbIFHPu (ORCPT + 28 others); Sun, 6 Sep 2015 03:15:50 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7331 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750888AbbIFHOj (ORCPT ); Sun, 6 Sep 2015 03:14:39 -0400 Received: from 172.24.1.48 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUK94015; Sun, 06 Sep 2015 15:14:05 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 15:13:54 +0800 From: Wang Nan To: , , , CC: , , , , , , , , , , , Subject: [PATCH 01/27] perf tools: Don't write to evsel if parser doesn't collect evsel Date: Sun, 6 Sep 2015 07:13:17 +0000 Message-ID: <1441523623-152703-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1441523623-152703-1-git-send-email-wangnan0@huawei.com> References: <1441523623-152703-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected 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: wangnan0@huawei.com 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.176 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: , If parse_events__scanner() collects no entry, perf_evlist__last(evlist) is invalid. Although it shouldn't happen at this point, before calling perf_evlist__last(), we should ensure the list is not empty for safety reason. There are 3 places need this checking: 1. Before setting cmdline_group_boundary; 2. Before __perf_evlist__set_leader(); 3. In foreach_evsel_in_last_glob. Signed-off-by: Wang Nan Reviewed-by: Masami Hiramatsu Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Jiri Olsa Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Link: https://lkml.kernel.org/n/1441176553-116129-1-git-send-email-wangnan0@huawei.com [wangnan: Enforce the assumption that parser never collect empty list] --- tools/perf/util/parse-events.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3840176..07ce501 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -793,6 +793,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; @@ -1143,10 +1148,16 @@ int parse_events(struct perf_evlist *evlist, const char *str, int entries = data.idx - evlist->nr_entries; struct perf_evsel *last; + if (list_empty(&data.list)) { + WARN_ONCE(true, "WARNING: event parser found nothing"); + return -1; + } + + last = list_entry(data.list.prev, struct perf_evsel, node); + last->cmdline_group_boundary = true; + 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; return 0; } @@ -1252,7 +1263,13 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist, struct perf_evsel *last = NULL; int err; - if (evlist->nr_entries > 0) + /* + * 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 (!list_empty(&evlist->entries)) last = perf_evlist__last(evlist); do {