diff mbox series

[v3,1/2] power: fix pstate base frequency handling

Message ID 20210401150614.234257-1-anatoly.burakov@intel.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series [v3,1/2] power: fix pstate base frequency handling | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

Burakov, Anatoly April 1, 2021, 3:06 p.m. UTC
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 mbox series

Patch

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,