power: fix coverity issue

Message ID 1554736884-12195-1-git-send-email-liang.j.ma@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series power: fix coverity issue |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Liang, Ma April 8, 2019, 3:21 p.m. UTC
  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 | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Hunt, David April 8, 2019, 3:32 p.m. UTC | #1
Hi Liang,

On 8/4/2019 4:21 PM, Liang Ma wrote:
> 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 | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/lib/librte_power/power_pstate_cpufreq.c b/lib/librte_power/power_pstate_cpufreq.c
> index 336c13869..db2f7a0f4 100644
> --- a/lib/librte_power/power_pstate_cpufreq.c
> +++ b/lib/librte_power/power_pstate_cpufreq.c
> @@ -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.
  

Patch

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