Skip to content

Commit

Permalink
perf evlist: Use cpu_map__nr() helper
Browse files Browse the repository at this point in the history
Use the cpu_map__nr() helper to protect a possible NULL cpu map
dereference.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1362987798-24969-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Mar 15, 2013
1 parent 334fe7a commit 8539795
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void perf_evlist__disable(struct perf_evlist *evlist)
int cpu, thread;
struct perf_evsel *pos;

for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
list_for_each_entry(pos, &evlist->entries, node) {
if (!perf_evsel__is_group_leader(pos))
continue;
Expand Down Expand Up @@ -443,7 +443,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
struct perf_evsel *evsel;
int cpu, thread;

for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
int output = -1;

for (thread = 0; thread < evlist->threads->nr; thread++) {
Expand All @@ -470,7 +470,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
return 0;

out_unmap:
for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
if (evlist->mmap[cpu].base != NULL) {
munmap(evlist->mmap[cpu].base, evlist->mmap_len);
evlist->mmap[cpu].base = NULL;
Expand Down Expand Up @@ -725,7 +725,7 @@ int perf_evlist__open(struct perf_evlist *evlist)

return 0;
out_err:
ncpus = evlist->cpus ? evlist->cpus->nr : 1;
ncpus = cpu_map__nr(evlist->cpus);
nthreads = evlist->threads ? evlist->threads->nr : 1;

list_for_each_entry_reverse(evsel, &evlist->entries, node)
Expand Down

0 comments on commit 8539795

Please sign in to comment.