perf evlist: Tidy duplicated munmap code
authorAdrian Hunter <[email protected]>
Thu, 4 Jul 2013 13:20:26 +0000 (16:20 +0300)
committerArnaldo Carvalho de Melo <[email protected]>
Fri, 12 Jul 2013 16:52:54 +0000 (13:52 -0300)
The same lines of code are used in three places.  Make it a new function
'__perf_evlist__munmap()'.

Signed-off-by: Adrian Hunter <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/evlist.c

index d8f34e0afbfb6e4abc11ff38c277e5501f2e7ce4..42ea4e947eb827ddd8e0ac490e0f2aa0a3d7630d 100644 (file)
@@ -403,16 +403,20 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
        return event;
 }
 
+static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
+{
+       if (evlist->mmap[idx].base != NULL) {
+               munmap(evlist->mmap[idx].base, evlist->mmap_len);
+               evlist->mmap[idx].base = NULL;
+       }
+}
+
 void perf_evlist__munmap(struct perf_evlist *evlist)
 {
        int i;
 
-       for (i = 0; i < evlist->nr_mmaps; i++) {
-               if (evlist->mmap[i].base != NULL) {
-                       munmap(evlist->mmap[i].base, evlist->mmap_len);
-                       evlist->mmap[i].base = NULL;
-               }
-       }
+       for (i = 0; i < evlist->nr_mmaps; i++)
+               __perf_evlist__munmap(evlist, i);
 
        free(evlist->mmap);
        evlist->mmap = NULL;
@@ -477,12 +481,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
        return 0;
 
 out_unmap:
-       for (cpu = 0; cpu < nr_cpus; cpu++) {
-               if (evlist->mmap[cpu].base != NULL) {
-                       munmap(evlist->mmap[cpu].base, evlist->mmap_len);
-                       evlist->mmap[cpu].base = NULL;
-               }
-       }
+       for (cpu = 0; cpu < nr_cpus; cpu++)
+               __perf_evlist__munmap(evlist, cpu);
        return -1;
 }
 
@@ -517,12 +517,8 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in
        return 0;
 
 out_unmap:
-       for (thread = 0; thread < nr_threads; thread++) {
-               if (evlist->mmap[thread].base != NULL) {
-                       munmap(evlist->mmap[thread].base, evlist->mmap_len);
-                       evlist->mmap[thread].base = NULL;
-               }
-       }
+       for (thread = 0; thread < nr_threads; thread++)
+               __perf_evlist__munmap(evlist, thread);
        return -1;
 }