Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3304012ybg; Sun, 20 Oct 2019 10:55:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo+vRrZS35EGwMd0MtcPB3KSU02ntltwgCX0A2hvOgEqdAi1D43ZkOpAKLR+iR5muBcXZf X-Received: by 2002:a50:8f03:: with SMTP id 3mr21308220edy.195.1571594144836; Sun, 20 Oct 2019 10:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571594144; cv=none; d=google.com; s=arc-20160816; b=VYd6FuNQ8hDev9b6V3kE0j2CXSt0Q6PivvpOgf/enP2tdf+UbaG6d2+DxQFIl+iygH JrVuCdSyUOfbgud/em9tStqWKeE08N9L+b8LA8h8lZjFvTlFYubwdDQRU/MIfTP2IYVi ZokBjW3NnseovI11Q92znNC7Fgt2YZcApE8eXGbWoD+nXJA+FV/ZaLyfePLv7ao/diwM 6Nly+1AEHQUrpT504KxeVyszCRcZEft6wR9IfQeMEtCIKDhQKsrscpRQIy5uIdt3PDGF HUO9MuL7BING54M583bRedB8zq0rO/P74jRSuJeIabcTHS/a10rtrH2nszZd+9DpBfds cz8g== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ImIKwdG4uIQOybV7F95px0I0+AYQwr5U5HDnO4v3fyA=; b=mZeNmkP+ars2Y7ssJpF/F3hgqU+KskWaf/zLBrlSln522C0MUZqRzj/po18Ghq1txM QMmMR7FRCXSq+w/CaioiIT8jSxMUVncsv3y6/RJr9Xj99123JPNX8KgCqMwoyQA1UKBq WhainyBqOkpBtDeMb11fnVB6ESNU00x9VfhoFQbDj2pxwk4bCDtoHWGir34Q/t+oM4aj JJPqE1BhtByER/jntNkebMa4AliJWN5YbzBfmfIiy6Bskd9jOFO1baz5UAySO6N/EDNf TQIYq12sgIGuRtPyphdx/HbAA6zi/Eqbk8/Aui8fXiU+WeGXlWtPf0NFMU2f59lZLNPk zZHg== 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 ym1si7074210ejb.263.2019.10.20.10.55.21; Sun, 20 Oct 2019 10:55:44 -0700 (PDT) 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 S1726922AbfJTRw7 (ORCPT + 99 others); Sun, 20 Oct 2019 13:52:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:24807 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbfJTRwb (ORCPT ); Sun, 20 Oct 2019 13:52:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Oct 2019 10:52:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,320,1566889200"; d="scan'208";a="200226298" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by orsmga003.jf.intel.com with ESMTP; 20 Oct 2019 10:52:30 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id 0BA71300393; Sun, 20 Oct 2019 10:52:30 -0700 (PDT) From: Andi Kleen To: acme@kernel.org Cc: linux-kernel@vger.kernel.org, jolsa@kernel.org, eranian@google.com, kan.liang@linux.intel.com, peterz@infradead.org, Andi Kleen Subject: [PATCH v2 2/9] perf evsel: Avoid close(-1) Date: Sun, 20 Oct 2019 10:51:55 -0700 Message-Id: <20191020175202.32456-3-andi@firstfloor.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191020175202.32456-1-andi@firstfloor.org> References: <20191020175202.32456-1-andi@firstfloor.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen 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 --- 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 a8cb582e2721..5a89857b0381 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 d831038b55f2..d4451846af93 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -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; -- 2.21.0