From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 30070A0548;
	Thu,  1 Apr 2021 17:05:23 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 6C6BD14136B;
	Thu,  1 Apr 2021 17:05:17 +0200 (CEST)
Received: from mga14.intel.com (mga14.intel.com [192.55.52.115])
 by mails.dpdk.org (Postfix) with ESMTP id 61125140EE8
 for <dev@dpdk.org>; Thu,  1 Apr 2021 17:05:15 +0200 (CEST)
IronPort-SDR: Hv3Vf4eN+qyKTrMzSYLR+tQ+WVYuYuAe3IIvbvyPPIr8uCNWgiGiZXOrJocOVbtxfJPJm7yT/a
 vWsHlexa1Ytw==
X-IronPort-AV: E=McAfee;i="6000,8403,9941"; a="191741119"
X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="191741119"
Received: from orsmga008.jf.intel.com ([10.7.209.65])
 by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 01 Apr 2021 08:05:02 -0700
IronPort-SDR: ZuJsFiXRmFYFFIFD6tqsPlsg26TZPyyit4c9Be8+blN2yMbf3vAEWJ6cVD1K6GAnYrNHU3DMlZ
 CRqrSi1dervQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.81,296,1610438400"; d="scan'208";a="419235786"
Received: from silpixa00399498.ir.intel.com (HELO
 silpixa00399498.ger.corp.intel.com) ([10.237.222.97])
 by orsmga008.jf.intel.com with ESMTP; 01 Apr 2021 08:05:00 -0700
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: anatoly.burakov@intel.com,
	david.hunt@intel.com
Date: Thu,  1 Apr 2021 15:04:59 +0000
Message-Id: <20210401150500.234015-1-anatoly.burakov@intel.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <d0dc49e5dab4d4c730cc137194350a7d0a8baca8.1617114301.git.anatoly.burakov@intel.com>
References: <d0dc49e5dab4d4c730cc137194350a7d0a8baca8.1617114301.git.anatoly.burakov@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v2 1/2] power: fix pstate base frequency handling
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Previous fix for base frequency handling in pstate mode introduced a
couple of issues:

- When base_frequency file does not exist, it simply bails out because
  of what appears to be accidental addition of FOPEN_OR_ERR_RET. This is
  incorrect, as absence of this file is not fatal and is in fact
  expected on kernel versions earlier than 5.3
- When base_frequency file does exist, it gets opened, but never gets
  closed, resulting in a resource leak

Both issues also manifest themselves as Coverity defects (dead code, and
a resource leak), so this fix addresses both.

Fixes: 4db9587bbf72 ("power: check sysfs base frequency")
Cc: david.hunt@intel.com

Coverity issue: 369693
Coverity issue: 369694
Bugzilla ID: 668

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_power/power_pstate_cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 8a1fffaed5..af5ad0b506 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -172,7 +172,6 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 			POWER_SYSFILE_BASE_MAX_FREQ,
 			pi->lcore_id);
 	f_base_max = fopen(fullpath_base_max, "r");
-	FOPEN_OR_ERR_RET(f_base_max, -1);
 	if (f_base_max != NULL) {
 		s_base_max = fgets(buf_base, sizeof(buf_base), f_base_max);
 		FOPS_OR_NULL_GOTO(s_base_max, out);
@@ -185,6 +184,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 		base_max_ratio =
 			strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL)
 				/ BUS_FREQ;
+		fclose(f_base_max);
 	}
 
 	snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,
-- 
2.25.1