From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932092AbcAIQbt (ORCPT ); Sat, 9 Jan 2016 11:31:49 -0500 Received: from terminus.zytor.com ([198.137.202.10]:41983 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756437AbcAIQbr (ORCPT ); Sat, 9 Jan 2016 11:31:47 -0500 Date: Sat, 9 Jan 2016 08:31:32 -0800 From: tip-bot for Jiri Olsa Message-ID: Cc: acme@redhat.com, mingo@kernel.org, namhyung@kernel.org, a.p.zijlstra@chello.nl, acme@kernel.org, dsahern@gmail.com, kan.liang@intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, jolsa@kernel.org, hpa@zytor.com Reply-To: a.p.zijlstra@chello.nl, acme@redhat.com, namhyung@kernel.org, mingo@kernel.org, dsahern@gmail.com, acme@kernel.org, kan.liang@intel.com, tglx@linutronix.de, jolsa@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org In-Reply-To: <1452077397-31958-2-git-send-email-jolsa@kernel.org> References: <1452077397-31958-2-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf cpumap: Fix cpu conversion in cpu_map__from_entries Git-Commit-ID: 15d2b9956b41ffb5961b897bf61cdc09f722dfbf 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: 15d2b9956b41ffb5961b897bf61cdc09f722dfbf Gitweb: http://git.kernel.org/tip/15d2b9956b41ffb5961b897bf61cdc09f722dfbf Author: Jiri Olsa AuthorDate: Wed, 6 Jan 2016 11:49:55 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 6 Jan 2016 20:11:16 -0300 perf cpumap: Fix cpu conversion in cpu_map__from_entries We can't convert u16 cpu_map_entries::cpu[x] value directly to int, because it could hold -1, which would be converted as 65535. Adding special treatment for -1, which is not real cpu number, to be converted to (int -1). Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Kan Liang Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1452077397-31958-2-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cpumap.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index a0717b9..fa93509 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -188,8 +188,17 @@ static struct cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus) if (map) { unsigned i; - for (i = 0; i < cpus->nr; i++) - map->map[i] = (int)cpus->cpu[i]; + for (i = 0; i < cpus->nr; i++) { + /* + * Special treatment for -1, which is not real cpu number, + * and we need to use (int) -1 to initialize map[i], + * otherwise it would become 65535. + */ + if (cpus->cpu[i] == (u16) -1) + map->map[i] = -1; + else + map->map[i] = (int) cpus->cpu[i]; + } } return map;