Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp405095ybc; Tue, 12 Nov 2019 03:22:08 -0800 (PST) X-Google-Smtp-Source: APXvYqx4qAON5lNfMmphWs1MJP/ImYR+7j+ftk45+mgqKkT46v/Tbyh7dosIpD66btqEJA3b9UtI X-Received: by 2002:a50:c408:: with SMTP id v8mr32087520edf.140.1573557727917; Tue, 12 Nov 2019 03:22:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573557727; cv=none; d=google.com; s=arc-20160816; b=ydDFExYXG7dBYYgJfLeh+E3X3zRhWM16cymDVlBVv9kXrDAwFgzqYEHoSvhTL2SjKt qPu5bexj7bEdYjPOqHZK3pSCkDGB3+XSQYVXKJ19wwwziBMcWdjVqHkBEHCxDwC4M8DN e+zw3lIZ6ihr83llsBApAVIXrE0BgOOzAE45HAn4GGPOVftC6T/PEUBfPKNo8DztU00W xLAUPmLRMp8A8gSLsHVXuh8/e86aFCr2cAofnH0JwuEap4IjNLSlQf5XVDWE9sf/f2a1 AhImv62gHGZQEbZZZsK68fe5Qhpa0c5PDkt3f0ARPhedzh793EQU4tvvh4u1B7K9izzS 58lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=E+P3DR4U8G0levvwItvb1ZPXDoIzTt65nADG8lU/sEk=; b=OhyaViFxvFojXXRwnATVN2EHM77QzK+cKizZk/w+pE2HPXmNbNSUolrlCpN7JlkoYb Kqx0hrD5OLgXWwn9n9SKXHM/iLuC9li2C9FWtH5k7REiTJWm8bZR92lYqHwBVbduxxTi L5PzCWcphzk0GpuHwwoIRP+7jRVsz65WH98tu02+Qyhjlk+pKDF8TpDivKZ2X37G6Yoo czwXIkerOcUM3OY6SGgOMqQ7SuLIl4U+gZvL5YYSJvr03CxN7pdFqmPG4YPV2ETzJdMw D+9N11xecDv6haUIfoXsH+sL7E+xz17qxg6ych+Tqme8g3ADs7EXDvXgcFBJNFt4XHC5 HjNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8si12270012ejc.104.2019.11.12.03.21.43; Tue, 12 Nov 2019 03:22:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbfKLLSj (ORCPT + 99 others); Tue, 12 Nov 2019 06:18:39 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:33992 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727542AbfKLLSb (ORCPT ); Tue, 12 Nov 2019 06:18:31 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iUUBh-0000iE-T2; Tue, 12 Nov 2019 12:18:22 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id D5DAA1C04E4; Tue, 12 Nov 2019 12:18:15 +0100 (CET) Date: Tue, 12 Nov 2019 11:18:15 -0000 From: "tip-bot2 for Andi Kleen" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf evsel: Avoid close(-1) Cc: Andi Kleen , Jiri Olsa , Kan Liang , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191020175202.32456-3-andi@firstfloor.org> References: <20191020175202.32456-3-andi@firstfloor.org> MIME-Version: 1.0 Message-ID: <157355749550.29376.6682935779950651002.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 2ccfb8bc2143ca347609d1d4434176d73a78d805 Gitweb: https://git.kernel.org/tip/2ccfb8bc2143ca347609d1d4434176d73a78d805 Author: Andi Kleen AuthorDate: Sun, 20 Oct 2019 10:51:55 -07:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Wed, 06 Nov 2019 15:43:05 -03:00 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: Andi Kleen Acked-by: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20191020175202.32456-3-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/lib/evsel.c | 3 ++- tools/perf/util/evsel.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c index a8cb582..5a89857 100644 --- a/tools/perf/lib/evsel.c +++ b/tools/perf/lib/evsel.c @@ -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; } } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d831038..d445184 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -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;