Commit 2ccfb8bc authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf evsel: Avoid close(-1)

In some weak fallback cases close can be called a lot with -1. Check for
this case and avoid calling close then.

This is mainly to shut up valgrind which complains about this case.
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20191020175202.32456-3-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 796c01a4
...@@ -120,6 +120,7 @@ void perf_evsel__close_fd(struct perf_evsel *evsel) ...@@ -120,6 +120,7 @@ void perf_evsel__close_fd(struct perf_evsel *evsel)
for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) { for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread)); close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1; FD(evsel, cpu, thread) = -1;
} }
......
...@@ -1815,6 +1815,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, ...@@ -1815,6 +1815,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
old_errno = errno; old_errno = errno;
do { do {
while (--thread >= 0) { while (--thread >= 0) {
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread)); close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1; FD(evsel, cpu, thread) = -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment