perf cpumap: Fix cpu conversion in cpu_map__from_entries
authorJiri Olsa <[email protected]>
Wed, 6 Jan 2016 10:49:55 +0000 (11:49 +0100)
committerArnaldo Carvalho de Melo <[email protected]>
Wed, 6 Jan 2016 23:11:16 +0000 (20:11 -0300)
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 <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/cpumap.c

index a0717b93d8f5baa8f54a2d80a2fa4ce6ad61f350..fa935093a599429011fa214c24645fd0230e3b3a 100644 (file)
@@ -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;