Skip to content

Commit cf7de25

Browse files
Aleksandr Mishinvireshk
authored andcommitted
cppc_cpufreq: Fix possible null pointer dereference
cppc_cpufreq_get_rate() and hisi_cppc_cpufreq_get_rate() can be called from different places with various parameters. So cpufreq_cpu_get() can return null as 'policy' in some circumstances. Fix this bug by adding null return check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a28b2bf ("cppc_cpufreq: replace per-cpu data array with a list") Signed-off-by: Aleksandr Mishin <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent b5e230a commit cf7de25

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,15 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
741741
{
742742
struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
743743
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
744-
struct cppc_cpudata *cpu_data = policy->driver_data;
744+
struct cppc_cpudata *cpu_data;
745745
u64 delivered_perf;
746746
int ret;
747747

748+
if (!policy)
749+
return -ENODEV;
750+
751+
cpu_data = policy->driver_data;
752+
748753
cpufreq_cpu_put(policy);
749754

750755
ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0);
@@ -822,10 +827,15 @@ static struct cpufreq_driver cppc_cpufreq_driver = {
822827
static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu)
823828
{
824829
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
825-
struct cppc_cpudata *cpu_data = policy->driver_data;
830+
struct cppc_cpudata *cpu_data;
826831
u64 desired_perf;
827832
int ret;
828833

834+
if (!policy)
835+
return -ENODEV;
836+
837+
cpu_data = policy->driver_data;
838+
829839
cpufreq_cpu_put(policy);
830840

831841
ret = cppc_get_desired_perf(cpu, &desired_perf);

0 commit comments

Comments
 (0)