Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753289AbbLNIjd (ORCPT ); Mon, 14 Dec 2015 03:39:33 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52620 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753153AbbLNIja (ORCPT ); Mon, 14 Dec 2015 03:39:30 -0500 Date: Mon, 14 Dec 2015 00:39:17 -0800 From: tip-bot for Wang Nan Message-ID: Cc: namhyung@kernel.org, jolsa@redhat.com, tglx@linutronix.de, wangnan0@huawei.com, lizefan@huawei.com, acme@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com Reply-To: acme@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, wangnan0@huawei.com, lizefan@huawei.com, jolsa@redhat.com, tglx@linutronix.de, namhyung@kernel.org In-Reply-To: <1449541544-67621-17-git-send-email-wangnan0@huawei.com> References: <1449541544-67621-17-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Clear struct machine during machine__init() Git-Commit-ID: 93b0ba3c60da89043ce2b9f601cd2b3da408903b 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: 2240 Lines: 64 Commit-ID: 93b0ba3c60da89043ce2b9f601cd2b3da408903b Gitweb: http://git.kernel.org/tip/93b0ba3c60da89043ce2b9f601cd2b3da408903b Author: Wang Nan AuthorDate: Tue, 8 Dec 2015 02:25:44 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 11 Dec 2015 09:32:41 -0300 perf tools: Clear struct machine during machine__init() There are so many test cases use stack allocated 'struct machine'. Including: test__hists_link test__hists_filter test__mmap_thread_lookup test__thread_mg_share test__hists_output test__hists_cumulate Also, in non-test code (for example, machine__new_host()) there are code use 'malloc()' to alloc struct machine. These are dangerous operations, cause some tests fail or hung in machines__exit(). For example, in machines__exit -> machine__destroy_kernel_maps -> map_groups__remove -> maps__remove -> pthread_rwlock_wrlock a incorrectly initialized lock causes unintended behavior. This patch memset(0) that structure in machine__init() to ensure all fields in 'struct machine' are initialized to zero. Signed-off-by: Wang Nan Cc: Jiri Olsa Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1449541544-67621-17-git-send-email-wangnan0@huawei.com [ Use memset, see 'man bzero' ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index f5882b8..1407d51 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -25,6 +25,7 @@ static void dsos__init(struct dsos *dsos) int machine__init(struct machine *machine, const char *root_dir, pid_t pid) { + memset(machine, 0, sizeof(*machine)); map_groups__init(&machine->kmaps, machine); RB_CLEAR_NODE(&machine->rb_node); dsos__init(&machine->dsos); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/