Skip to content

Commit 95c3656

Browse files
WangNan0acmel
authored andcommitted
perf record: Ensure return non-zero rc when mmap fail
perf_evlist__mmap_ex() can fail without setting errno (for example, fail in condition checking. In this case all syscall is success). If this happen, record__open() incorrectly returns 0. Force setting rc is a quick way to avoid this problem, or we have to follow all possible code path in perf_evlist__mmap_ex() to make sure there's at least one system call before returning an error. Signed-off-by: Wang Nan <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: He Kuang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Li Zefan <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: He Kuang <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e1ab48b commit 95c3656

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/perf/builtin-record.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ static int record__open(struct record *rec)
324324
} else {
325325
pr_err("failed to mmap with %d (%s)\n", errno,
326326
strerror_r(errno, msg, sizeof(msg)));
327-
rc = -errno;
327+
if (errno)
328+
rc = -errno;
329+
else
330+
rc = -EINVAL;
328331
}
329332
goto out;
330333
}

0 commit comments

Comments
 (0)