[v2,1/1] power: fix potential null dereferences

Message ID 634db86689fc6a6ff28c5e59aff340d81f711a42.1625846156.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2,1/1] power: fix potential null dereferences |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing warning Testing issues
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Anatoly Burakov July 9, 2021, 3:55 p.m. UTC
  Currently, the error paths can lead to attempts at dereferencing NULL
pointers. Add the check to avoid attempts at dereferencing NULL
pointers.

Coverity issue: 371895
Coverity issue: 371889
Fixes: 06cffd468fdd ("power: refactor ACPI and intel_pstate support")
Cc: anatoly.burakov@intel.com

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
 lib/power/power_pstate_cpufreq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

David Marchand July 20, 2021, 3:21 p.m. UTC | #1
On Fri, Jul 9, 2021 at 5:57 PM Anatoly Burakov
<anatoly.burakov@intel.com> wrote:
>
> Currently, the error paths can lead to attempts at dereferencing NULL
> pointers. Add the check to avoid attempts at dereferencing NULL
> pointers.
>
> Coverity issue: 371895
> Coverity issue: 371889
> Fixes: 06cffd468fdd ("power: refactor ACPI and intel_pstate support")
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
  

Patch

diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index ba28ddcfca..3b607515fd 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -440,8 +440,10 @@  power_get_available_freqs(struct pstate_power_info *pi)
 			num_freqs, pi->lcore_id);
 
 out:
-	fclose(f_min);
-	fclose(f_max);
+	if (f_min != NULL)
+		fclose(f_min);
+	if (f_max != NULL)
+		fclose(f_max);
 
 	return ret;
 }