Skip to content

Commit 15d2b99

Browse files
olsajiriacmel
authored andcommitted
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 <acme@kernel.org> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1452077397-31958-2-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent aef9026 commit 15d2b99

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎tools/perf/util/cpumap.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,17 @@ static struct cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus)
188188
if (map) {
189189
unsigned i;
190190

191-
for (i = 0; i < cpus->nr; i++)
192-
map->map[i] = (int)cpus->cpu[i];
191+
for (i = 0; i < cpus->nr; i++) {
192+
/*
193+
* Special treatment for -1, which is not real cpu number,
194+
* and we need to use (int) -1 to initialize map[i],
195+
* otherwise it would become 65535.
196+
*/
197+
if (cpus->cpu[i] == (u16) -1)
198+
map->map[i] = -1;
199+
else
200+
map->map[i] = (int) cpus->cpu[i];
201+
}
193202
}
194203

195204
return map;

0 commit comments

Comments
 (0)