cpufreq: Fix issue found by coverity in drivers/cpufreq/cpufreq_stats.c
PATCH 1/1 cpufreq: Fix issue found by coverity in drivers/cpufreq/cpufreq_stats.c
This fixes an issue found in drivers/cpufreq/cpufreq_stats.c by Coverity. Please review as I'm not sure if -EINVAL is the correct value to return at this point.
Error reported:
CID: 2642
Checker: NULL_RETURNS (help)
File: /export2/p4-coverity/mc2/linux26/drivers/cpufreq/cpufreq_stats.c
Function: cpufreq_stats_create_table
Description: Dereferencing NULL value "data"
Patch description:
The return of cpufreq_cpu_get can be NULL, check return code and return -EINVAL if it is NULL.
---
cpufreq_stats.c | 6 ++++++ 1 files changed, 6 insertions(+)
drivers/cpufreq/cpufreq_stats.c +6 -0
@@ -197,6 +197,11 @@memset (stat,0 ,sizeof (struct cpufreq_stats )); data =cpufreq_cpu_get (cpu); +if (data ==NULL ) { + ret = -EINVAL ; + goto error_get_fail; + } +if ((ret =sysfs_create_group (&data->kobj, &stats_attr_group))) goto error_out;
@@ -244,6 +249,7 @@return 0 ; error_out:cpufreq_cpu_put (data); +error_get_fail:kfree (stat); cpufreq_stats_table[cpu] =NULL ;return ret;
Quoted 2 lines · Jayachandran C.
This fixes an issue found in
drivers/cpufreq/cpufreq_stats.cby Coverity. Please review as I'm not sure if-EINVALis the correct value to return at this point.
Yep, EINVAL is fine. I checked this into the cpufreq-git tree (though I did it by hand as it's changed there recently
-- working against the -mm tree would save you this hassle in future btw).
Thanks
Dave