lkml.org 
[lkml]   [2011]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 8/8] perf evlist: Fix error handling on perf_event__mmap
Date
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@gmail.com>
---
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


\
 
 \ /
  Last update: 2011-12-12 16:21    [W:0.084 / U:1.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site