[PATCH 8/8] perf evlist: Fix error handling on perf_event__mmap

From: Namhyung Kim
Date: Mon Dec 12 2011 - 10:17:49 EST


If mmap syscall fails for some reason, @evlist->mmap->base wil
have the value of MAP_FAILED. Since it is defined as -1, it'll
cause a subsequent munmap failure, so the original errno will
be lost. Fix it.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxx>
---
tools/perf/util/evlist.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8b19e7a1e881..5b7b3eeafb8d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -487,7 +487,9 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m

out_unmap:
for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
- if (evlist->mmap[cpu].base != NULL) {
+ if (evlist->mmap[cpu].base == MAP_FAILED) {
+ evlist->mmap[cpu].base = NULL;
+ } else if (evlist->mmap[cpu].base != NULL) {
munmap(evlist->mmap[cpu].base, evlist->mmap_len);
evlist->mmap[cpu].base = NULL;
}
@@ -526,7 +528,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in

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

--
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/