From patchwork Mon Jun 5 18:01:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 13267840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 971D7C7EE25 for ; Mon, 5 Jun 2023 18:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234769AbjFESCd (ORCPT ); Mon, 5 Jun 2023 14:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234800AbjFESCY (ORCPT ); Mon, 5 Jun 2023 14:02:24 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC452F9; Mon, 5 Jun 2023 11:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685988143; x=1717524143; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfPvkmzWJcJdc6LqGPirAEzeqOxBh6wxev3IG7Dp8Fo=; b=JRTvNRAvtis4Iuzu5jWuQknTkfUv0iBjpLOK+i60bssRhnjg+iOFGXb8 J2SW+oeSEDMHNeGToQT0OxW/5gPGQ2Sg6mI7OLhlIEBP5Bst1eSg3gZS7 /WArnn+H94Nb6uxcBfvkbARB0y+TkzWx83axuuyxGzmS+hygOHLFDcedH CGsbn73xTVg3/Gqn+lz32u4HP+IKBjgqsIP1mNlWkeD0WWrcsy+G96UYq CsH74YOqPTwJS9LzvQZxjZvzLreOyj6ovD/u8w4oRS//S2nfetjLPg/jy q4PVgOtZEC9a60YFwuok+zhB+VRFocr283XSF1j3+t8XRDBO/7b0/VfMx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="442814910" X-IronPort-AV: E=Sophos;i="6.00,218,1681196400"; d="scan'208";a="442814910" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 11:02:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="821274036" X-IronPort-AV: E=Sophos;i="6.00,218,1681196400"; d="scan'208";a="821274036" Received: from gfittedx-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.47.115]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 11:02:08 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , Sai Praneeth Prakhya , Babu Moger , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v3 04/19] selftests/resctrl: Close perf value read fd on errors Date: Mon, 5 Jun 2023 21:01:30 +0300 Message-Id: <20230605180145.112924-5-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230605180145.112924-1-ilpo.jarvinen@linux.intel.com> References: <20230605180145.112924-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Perf event fd (fd_lm) is not closed on some error paths. Always close fd_lm in get_llc_perf() and add close into an error handling block in cat_val(). Fixes: 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 8a4fe8693be6..ced47b445d1e 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -87,21 +87,20 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no) static int get_llc_perf(unsigned long *llc_perf_miss) { __u64 total_misses; + int ret; /* Stop counters after one span to get miss rate */ ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) { + ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); + close(fd_lm); + if (ret == -1) { perror("Could not get llc misses through perf"); - return -1; } total_misses = rf_cqm.values[0].value; - - close(fd_lm); - *llc_perf_miss = total_misses; return 0; @@ -253,6 +252,7 @@ int cat_val(struct resctrl_val_param *param) memflush, operation, resctrl_val)) { fprintf(stderr, "Error-running fill buffer\n"); ret = -1; + close(fd_lm); break; }