perf evsel: Avoid close(-1)
authorAndi Kleen <ak@linux.intel.com>
Sun, 20 Oct 2019 17:51:55 +0000 (10:51 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 Nov 2019 18:43:05 +0000 (15:43 -0300)
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>
tools/perf/lib/evsel.c
tools/perf/util/evsel.c

index a8cb582e2721dc15258b5c518abee682618ffb6b..5a89857b0381ce23aaceb9ddd2f44647b8bfb2af 100644 (file)
@@ -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;
                }
 }
index d831038b55f2824bd66d165f9a4bb420b4e7aa52..d4451846af93ac75ac9cb85449d043f7e1e47033 100644 (file)
@@ -1815,7 +1815,8 @@ out_close:
        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;