Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752968AbdCOSlC (ORCPT ); Wed, 15 Mar 2017 14:41:02 -0400 Received: from terminus.zytor.com ([65.50.211.136]:39148 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbdCOSk2 (ORCPT ); Wed, 15 Mar 2017 14:40:28 -0400 Date: Wed, 15 Mar 2017 11:37:23 -0700 From: tip-bot for Changbin Du Message-ID: Cc: ak@linux.intel.com, tglx@linutronix.de, acme@redhat.com, hpa@zytor.com, changbin.du@intel.com, peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@kernel.org, changbin.du@intel.com, hpa@zytor.com, acme@redhat.com, tglx@linutronix.de, ak@linux.intel.com In-Reply-To: <20170313083148.23568-1-changbin.du@intel.com> References: <20170313083148.23568-1-changbin.du@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf sort: Fix segfault with basic block 'cycles' sort dimension Git-Commit-ID: 4b0b3aa6a2756e6115fdf275c521e4552a7082f3 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 Content-Length: 1976 Lines: 51 Commit-ID: 4b0b3aa6a2756e6115fdf275c521e4552a7082f3 Gitweb: http://git.kernel.org/tip/4b0b3aa6a2756e6115fdf275c521e4552a7082f3 Author: Changbin Du AuthorDate: Mon, 13 Mar 2017 16:31:48 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 13 Mar 2017 11:41:20 -0300 perf sort: Fix segfault with basic block 'cycles' sort dimension Skip the sample which doesn't have branch_info to avoid segmentation fault: The fault can be reproduced by: perf record -a perf report -F cycles Signed-off-by: Changbin Du Tested-by: Arnaldo Carvalho de Melo Cc: Andi Kleen Cc: Peter Zijlstra Fixes: 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field") Link: http://lkml.kernel.org/r/20170313083148.23568-1-changbin.du@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/sort.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index f8f16c0..93f755a 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf, static int64_t sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right) { + if (!left->branch_info || !right->branch_info) + return cmp_null(left->branch_info, right->branch_info); + return left->branch_info->flags.cycles - right->branch_info->flags.cycles; } @@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right) static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { + if (!he->branch_info) + return scnprintf(bf, size, "%-.*s", width, "N/A"); if (he->branch_info->flags.cycles == 0) return repsep_snprintf(bf, size, "%-*s", width, "-"); return repsep_snprintf(bf, size, "%-*hd", width,