[v2] power: fix coverity issue

Message ID 1554740356-13914-1-git-send-email-liang.j.ma@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] power: fix coverity issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Liang, Ma April 8, 2019, 4:19 p.m. UTC
  Fix the resource leaking issue

Coverity issue: 337668

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

Signed-off-by: Liang Ma <liang.j.ma@intel.com>
---
 lib/librte_power/power_pstate_cpufreq.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
  

Comments

Hunt, David May 3, 2019, 9:26 a.m. UTC | #1
On 8/4/2019 5:19 PM, Liang Ma wrote:
> Fix the resource leaking issue
>
> Coverity issue: 337668
>
> Fixes: b60fd5f8b1ce8f0a2c ("power: add bit for high frequency cores")
>
> Signed-off-by: Liang Ma <liang.j.ma@intel.com>
> ---
>   lib/librte_power/power_pstate_cpufreq.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
> index 336c13869..07ca5c1dd 100644
> --- a/lib/librte_power/power_pstate_cpufreq.c
> +++ b/lib/librte_power/power_pstate_cpufreq.c
> @@ -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


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

Tested-by: David Hunt <david.hunt@intel.com>
  
Thomas Monjalon May 9, 2019, 6:46 p.m. UTC | #2
03/05/2019 11:26, Hunt, David:
> On 8/4/2019 5:19 PM, Liang Ma wrote:
> > 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
> 
> Tested-by: David Hunt <david.hunt@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
index 336c13869..07ca5c1dd 100644
--- a/lib/librte_power/power_pstate_cpufreq.c
+++ b/lib/librte_power/power_pstate_cpufreq.c
@@ -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