From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752031AbdH2VYV (ORCPT ); Tue, 29 Aug 2017 17:24:21 -0400 Received: from terminus.zytor.com ([65.50.211.136]:45877 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752001AbdH2VYT (ORCPT ); Tue, 29 Aug 2017 17:24:19 -0400 Date: Tue, 29 Aug 2017 14:21:59 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: mark.rutland@arm.com, mingo@kernel.org, a.p.zijlstra@chello.nl, andi@firstfloor.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, jolsa@kernel.org, dsahern@gmail.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, hpa@zytor.com, acme@redhat.com Reply-To: mark.rutland@arm.com, mingo@kernel.org, a.p.zijlstra@chello.nl, andi@firstfloor.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, jolsa@kernel.org, dsahern@gmail.com, hpa@zytor.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, acme@redhat.com In-Reply-To: <20170824162737.7813-9-jolsa@kernel.org> References: <20170824162737.7813-9-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf values: Zero value buffers Git-Commit-ID: a1834fc938344dd3015a1df64ee7f2af70ded147 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 Commit-ID: a1834fc938344dd3015a1df64ee7f2af70ded147 Gitweb: http://git.kernel.org/tip/a1834fc938344dd3015a1df64ee7f2af70ded147 Author: Jiri Olsa AuthorDate: Thu, 24 Aug 2017 18:27:35 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 28 Aug 2017 16:44:43 -0300 perf values: Zero value buffers We need to make sure the array of value pointers are zero initialized, because we use them in realloc later on and uninitialized non zero value will cause allocation error and aborted execution. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: David Ahern Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20170824162737.7813-9-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/values.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c index 2c4af02..3b56aea 100644 --- a/tools/perf/util/values.c +++ b/tools/perf/util/values.c @@ -12,7 +12,7 @@ int perf_read_values_init(struct perf_read_values *values) values->threads_max = 16; values->pid = malloc(values->threads_max * sizeof(*values->pid)); values->tid = malloc(values->threads_max * sizeof(*values->tid)); - values->value = malloc(values->threads_max * sizeof(*values->value)); + values->value = zalloc(values->threads_max * sizeof(*values->value)); if (!values->pid || !values->tid || !values->value) { pr_debug("failed to allocate read_values threads arrays"); goto out_free_pid; @@ -99,7 +99,8 @@ static int perf_read_values__findnew_thread(struct perf_read_values *values, } i = values->threads; - values->value[i] = malloc(values->counters_max * sizeof(**values->value)); + + values->value[i] = zalloc(values->counters_max * sizeof(**values->value)); if (!values->value[i]) { pr_debug("failed to allocate read_values counters array"); return -ENOMEM; @@ -130,12 +131,16 @@ static int perf_read_values__enlarge_counters(struct perf_read_values *values) for (i = 0; i < values->threads; i++) { u64 *value = realloc(values->value[i], counters_max * sizeof(**values->value)); + int j; if (!value) { pr_debug("failed to enlarge read_values ->values array"); goto out_free_name; } + for (j = values->counters_max; j < counters_max; j++) + value[j] = 0; + values->value[i] = value; }