Skip to content

Commit

Permalink
perf evsel: Avoid close(-1)
Browse files Browse the repository at this point in the history
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: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Andi Kleen authored and Arnaldo Carvalho de Melo committed Nov 6, 2019
1 parent 796c01a commit 2ccfb8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tools/perf/lib/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ void perf_evsel__close_fd(struct perf_evsel *evsel)

for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
close(FD(evsel, cpu, thread));
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,8 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
old_errno = errno;
do {
while (--thread >= 0) {
close(FD(evsel, cpu, thread));
if (FD(evsel, cpu, thread) >= 0)
close(FD(evsel, cpu, thread));
FD(evsel, cpu, thread) = -1;
}
thread = nthreads;
Expand Down

0 comments on commit 2ccfb8b

Please sign in to comment.