From patchwork Mon Sep 14 10:23:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53543 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id C27C22056A for ; Mon, 14 Sep 2015 10:24:32 +0000 (UTC) Received: by lamp12 with SMTP id p12sf45775459lam.2 for ; Mon, 14 Sep 2015 03:24:31 -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=EiwSYQLXrpuL4OrzqQhNMRyMN6BQA51L//6mZ4LsevA=; b=U92yWUgptPk+IpXZ2aUQr04AWpf9nLLBlUhux3JFxODPEbaQeqdUcdbBVU+tUWtjBI sp/Z3To1A0bTuQsAQPUR1vjm+8+BjIB8FoGDvSXOalxirvvWvmOEwGkhcOZ3ErA3W8K+ XWpXcfD4NCt3u4PtA8BD/MktHgl0/IfrctdIXOgiFj5NaKtSBUsH1Dw70a0L6XYtqok+ 0nvcSOXEeXBIF/OecvukRun4fYg+at/uDpO0+reDmuil1SAAV1VkQa+BjvVtpanTTdb6 m+Y7/vvKus599iluiHr3IoXxe1W20xITAm4owRD8Kx4iYkot+Vof1wuraYaXVP8fD6Xw oTVg== X-Gm-Message-State: ALoCoQnLwaGXBGUWzYqcxZIte+osYGEty3xuhSxh4yyxGx3zzIOQb6wdkfsbxvcyzNvVLluNxASn X-Received: by 10.112.140.195 with SMTP id ri3mr2923039lbb.22.1442226270947; Mon, 14 Sep 2015 03:24:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.170 with SMTP id x10ls609236lal.61.gmail; Mon, 14 Sep 2015 03:24:30 -0700 (PDT) X-Received: by 10.112.17.105 with SMTP id n9mr5200080lbd.78.1442226270763; Mon, 14 Sep 2015 03:24:30 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id bw10si9226705lbc.114.2015.09.14.03.24.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 03:24:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lahg1 with SMTP id g1so53723679lah.1 for ; Mon, 14 Sep 2015 03:24:30 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr7743283lbb.56.1442226270615; Mon, 14 Sep 2015 03:24:30 -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 w3csp1111002lbq; Mon, 14 Sep 2015 03:24:29 -0700 (PDT) X-Received: by 10.66.141.199 with SMTP id rq7mr33620800pab.140.1442226269503; Mon, 14 Sep 2015 03:24:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pi6si22451419pbb.92.2015.09.14.03.24.28; Mon, 14 Sep 2015 03:24:29 -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 S1755013AbbINKY1 (ORCPT + 29 others); Mon, 14 Sep 2015 06:24:27 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:3133 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753345AbbINKYZ (ORCPT ); Mon, 14 Sep 2015 06:24:25 -0400 Received: from 172.24.1.48 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BMV74757; Mon, 14 Sep 2015 18:24:07 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Mon, 14 Sep 2015 18:24:00 +0800 From: Wang Nan To: , CC: , , , Wang Nan Subject: [PATCH v2] perf tools: Fix segfault in 'perf top' Date: Mon, 14 Sep 2015 10:23:55 +0000 Message-ID: <1442226235-117265-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <20150911162207.GD3447@danjae.kornet> References: <20150911162207.GD3447@danjae.kornet> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0206.55F6A04E.029D, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: da6c8953028c5f294e2ef00f82292a95 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.215.46 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: , 'perf top' segfaults with following operation: # perf top -e page-faults -p 11400 # 11400 never generates page-fault Then on the resulting empty interface, press right key: # ./perf top -e page-faults -p 11400 perf: Segmentation fault -------- backtrace -------- ./perf[0x535428] /lib64/libc.so.6(+0x3545f)[0x7f0dd360745f] ./perf[0x531d46] ./perf(perf_evlist__tui_browse_hists+0x96)[0x5340d6] ./perf[0x44ba2f] /lib64/libpthread.so.0(+0x81d0)[0x7f0dd49dc1d0] /lib64/libc.so.6(clone+0x6c)[0x7f0dd36b90dc] The bug reside in perf_evsel__hists_browse() that, in the above circumstance browser->selection can be NULL, but code after skip_annotation doesn't consider it. This patch fix it by checking browser->selection before fetching browser->selection->map. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Namhyung Kim --- tools/perf/ui/browsers/hists.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index e4fd40f..182b87a 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2017,7 +2017,8 @@ skip_annotation: &options[nr_options], dso); nr_options += add_map_opt(browser, &actions[nr_options], &options[nr_options], - browser->selection->map); + browser->selection ? + browser->selection->map : NULL); nr_options += add_socket_opt(browser, &actions[nr_options], &options[nr_options], socket); @@ -2027,6 +2028,15 @@ skip_annotation: &actions[nr_options], &options[nr_options], thread, NULL); + /* + * Note that browser->selection != NULL + * when browser->he_selection is not NULL, + * so we don't need to check browser->selection + * before fetching browser->selection->sym like what + * we do before fetching browser->selection->map. + * + * See hist_browser__show_entry. + */ nr_options += add_script_opt(browser, &actions[nr_options], &options[nr_options],