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

Message ID 20210402092645.258257-1-anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v4,1/2] power: fix pstate base frequency handling |

Checks

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

Commit Message

Burakov, Anatoly April 2, 2021, 9:26 a.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(-)
  

Comments

Burakov, Anatoly April 2, 2021, 9:35 a.m. UTC | #1
On 02-Apr-21 10:26 AM, Anatoly Burakov wrote:
> 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>
> ---

For some reason git notes got lost on format-patch.

v3:
- Split refactor from bugfixes
v4:
- v3 was erroneously "fixing" handling of base max rather than base 
frequency
  
Pattan, Reshma April 2, 2021, 11:12 a.m. UTC | #2
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Burakov, Anatoly
> Sent: Friday, April 2, 2021 10:36 AM
> To: dev@dpdk.org
> Cc: Hunt, David <david.hunt@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v4 1/2] power: fix pstate base frequency
> handling
> 
> On 02-Apr-21 10:26 AM, Anatoly Burakov wrote:
> > 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.
> > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> > ---

Acked-by: Reshma Pattan <reshma.pattan@intel.com>
  

Patch

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 8a1fffaed5..c4639e4b8a 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -206,7 +206,6 @@  power_init_for_setting_freq(struct pstate_power_info *pi)
 			pi->lcore_id);
 
 	f_base = fopen(fullpath_base, "r");
-	FOPEN_OR_ERR_RET(f_base, -1);
 	if (f_base == NULL) {
 		/* No sysfs base_frequency, that's OK, continue without */
 		base_ratio = 0;
@@ -221,6 +220,7 @@  power_init_for_setting_freq(struct pstate_power_info *pi)
 
 		base_ratio = strtoul(buf_base, NULL, POWER_CONVERT_TO_DECIMAL)
 				/ BUS_FREQ;
+		fclose(f_base);
 	}
 
 	/* Add MSR read to detect turbo status */