From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751737AbbF3Ew5 (ORCPT ); Tue, 30 Jun 2015 00:52:57 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38396 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbbF3Ewv (ORCPT ); Tue, 30 Jun 2015 00:52:51 -0400 Date: Mon, 29 Jun 2015 21:52:30 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: eranian@google.com, linux-kernel@vger.kernel.org, ak@linux.intel.com, mingo@kernel.org, namhyung@kernel.org, hpa@zytor.com, adrian.hunter@intel.com, jolsa@kernel.org, a.p.zijlstra@chello.nl, dsahern@gmail.com, tglx@linutronix.de, acme@redhat.com Reply-To: tglx@linutronix.de, acme@redhat.com, jolsa@kernel.org, a.p.zijlstra@chello.nl, dsahern@gmail.com, adrian.hunter@intel.com, hpa@zytor.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, eranian@google.com, ak@linux.intel.com, mingo@kernel.org In-Reply-To: <1435310967-14570-2-git-send-email-jolsa@kernel.org> References: <1435310967-14570-2-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf thread_map: Introduce thread_map__reset function Git-Commit-ID: 62eea464380633b88902da35bf9cbd8515289703 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: 62eea464380633b88902da35bf9cbd8515289703 Gitweb: http://git.kernel.org/tip/62eea464380633b88902da35bf9cbd8515289703 Author: Jiri Olsa AuthorDate: Fri, 26 Jun 2015 11:29:06 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 26 Jun 2015 11:03:41 -0300 perf thread_map: Introduce thread_map__reset function We need to reset newly allocated 'struct thread_map_data' entries, because we will introduce new comm memeber, which will get set later or not at all. Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1435310967-14570-2-git-send-email-jolsa@kernel.org [ Use sizeof(map->map[0]) to be independent of the array entry type ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread_map.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 368cc58..ed76c17 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -21,11 +21,26 @@ static int filter(const struct dirent *dir) return 1; } +static void thread_map__reset(struct thread_map *map, int start, int nr) +{ + size_t size = (nr - start) * sizeof(map->map[0]); + + memset(&map->map[start], 0, size); +} + static struct thread_map *thread_map__realloc(struct thread_map *map, int nr) { size_t size = sizeof(*map) + sizeof(map->map[0]) * nr; + int start = map ? map->nr : 0; - return realloc(map, size); + map = realloc(map, size); + /* + * We only realloc to add more items, let's reset new items. + */ + if (map) + thread_map__reset(map, start, nr); + + return map; } #define thread_map__alloc(__nr) thread_map__realloc(NULL, __nr)