[PATCH 2/4] perf, tool: Factor evlist code to use global unmap function

From: Jiri Olsa
Date: Fri Dec 09 2011 - 12:30:56 EST


Using __perf_evlist__munmap in case of map failure rather
than duplicate the unmap code.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/evlist.c | 20 +++++++-------------
1 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f3178bc..56f1d34 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -416,7 +416,7 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
return event;
}

-void perf_evlist__munmap(struct perf_evlist *evlist)
+static void __perf_evlist__munmap(struct perf_evlist *evlist)
{
int i;

@@ -426,7 +426,11 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
evlist->mmap[i].base = NULL;
}
}
+}

+void perf_evlist__munmap(struct perf_evlist *evlist)
+{
+ __perf_evlist__munmap(evlist);
free(evlist->mmap);
evlist->mmap = NULL;
}
@@ -494,12 +498,7 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist)
return 0;

out_unmap:
- for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
- if (evlist->mmap[cpu].base != NULL) {
- munmap(evlist->mmap[cpu].base, evlist->mmap_len);
- evlist->mmap[cpu].base = NULL;
- }
- }
+ __perf_evlist__munmap(evlist);
return -1;
}

@@ -533,12 +532,7 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist)
return 0;

out_unmap:
- for (thread = 0; thread < evlist->threads->nr; thread++) {
- if (evlist->mmap[thread].base != NULL) {
- munmap(evlist->mmap[thread].base, evlist->mmap_len);
- evlist->mmap[thread].base = NULL;
- }
- }
+ __perf_evlist__munmap(evlist);
return -1;
}

--
1.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/