Skip to contentSkip to conversation

power: fix coverity issue

PATCH Superseded Liang Ma 3 participants 5 messages Apr 8, 2019 – May 9, 2019

lore
Share & tools
lore

Liang Ma

author
#0 lore raw

PATCH 1/1 power: fix coverity issue

Coverity issue: 337668

Fixes b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")
---
 lib/librte_power/power_pstate_cpufreq.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_power/power_pstate_cpufreq.c +3 -0
index 336c13869..db2f7a0f4 100644
@@ -197,6 +197,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 				/ BUS_FREQ;
 	}
 
+	if (f_base != NULL)
+		fclose(f_base);
+
 	/* Add MSR read to detect turbo status */
 
 	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)
Signature · 1 line
2.17.2
#1 lore raw

Hi Liang,

Quoted 14 lines · Liang Ma

Coverity issue: 337668

Fixes b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")
---
  lib/librte_power/power_pstate_cpufreq.c | 3 +++
  1 file changed, 3 insertions(+)
lib/librte_power/power_pstate_cpufreq.c +0 -0
index 336c13869..db2f7a0f4 100644

lib/librte_power/power_pstate_cpufreq.c power_init_for_setting_freq(struct pstate_power_info *pi) · line 205

Quoted 9 lines
lib/librte_power/power_pstate_cpufreq.c +3 -0
@@ -197,6 +197,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
  				/ BUS_FREQ;
  	}
 
+	if (f_base != NULL)
+		fclose(f_base);
+
  	/* Add MSR read to detect turbo status */
 
  	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)

Rather than adding a new 'if' statement, you could just add the fclose() to the previous section, which checks for a similar condition. Maybe just after the FOPS_OR_NULL_GOTO() (line 189).

Rgds,
Dave.

author
#2 lore raw

PATCH v2 1/1 power: fix coverity issue

In reply to Liang Ma

Fix the resource leaking issue

Coverity issue: 337668

Fixes b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")
---
 lib/librte_power/power_pstate_cpufreq.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
lib/librte_power/power_pstate_cpufreq.c +8 -3
index 336c13869..07ca5c1dd 100644
@@ -158,6 +158,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 	char *s_base;
 	uint32_t base_ratio = 0;
 	uint64_t max_non_turbo = 0;
+	int  ret_val = 0;
 
 	snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,
 			pi->lcore_id);
@@ -199,8 +200,10 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 
 	/* Add MSR read to detect turbo status */
 
-	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)
-		return -1;
+	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0) {
+		ret_val = -1;
+		goto out;
+	}
 
 	max_non_turbo = (max_non_turbo&NON_TURBO_MASK)>>NON_TURBO_OFFSET;
 
@@ -219,7 +222,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 	pi->core_base_freq = base_ratio * BUS_FREQ;
 
 out:
-	return 0;
+	if (f_base != NULL)
+		fclose(f_base);
+	return ret_val;
 }
 
 static int
Signature · 1 line
2.17.2
Tested-by on v2 1/1
#3 lore raw
Quoted 37 lines · Liang Ma

Fix the resource leaking issue

Coverity issue: 337668

Fixes b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")
---
  lib/librte_power/power_pstate_cpufreq.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
lib/librte_power/power_pstate_cpufreq.c +5 -2
index 336c13869..07ca5c1dd 100644
@@ -158,6 +158,7 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
  	char *s_base;
  	uint32_t base_ratio = 0;
  	uint64_t max_non_turbo = 0;
+	int  ret_val = 0;
 
  	snprintf(fullpath_min, sizeof(fullpath_min), POWER_SYSFILE_MIN_FREQ,
  			pi->lcore_id);
@@ -199,8 +200,10 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
 
  	/* Add MSR read to detect turbo status */
 
-	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0)
-		return -1;
+	if (power_rdmsr(PLATFORM_INFO, &max_non_turbo, pi->lcore_id) < 0) {
+		ret_val = -1;
+		goto out;
+	}
 
  	max_non_turbo = (max_non_turbo&NON_TURBO_MASK)>>NON_TURBO_OFFSET;
 

lib/librte_power/power_pstate_cpufreq.c power_init_for_setting_freq(struct pstate_power_info *pi) · line 230

Quoted 10 lines
lib/librte_power/power_pstate_cpufreq.c +3 -1
@@ -219,7 +222,9 @@ power_init_for_setting_freq(struct pstate_power_info *pi)
  	pi->core_base_freq = base_ratio * BUS_FREQ;
 
  out:
-	return 0;
+	if (f_base != NULL)
+		fclose(f_base);
+	return ret_val;
  }
 
  static int

Confirmed that this issue is resolved by testing on our internel Coverity server here, version 8.7.1

#4 lore raw

03/05/2019 11:26, Hunt, David:

Quoted 11 lines · Liang Ma
Quoted 5 lines

Fix the resource leaking issue

Coverity issue: 337668

Fixes b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")

Confirmed that this issue is resolved by testing on our internel Coverity server here, version 8.7.1

Applied, thanks