Skip to content

Commit c283755

Browse files
Jacob Shinrafaeljw
authored andcommitted
cpufreq: fix NULL pointer deference at od_set_powersave_bias()
When initializing the default powersave_bias value, we need to first make sure that this policy is running the ondemand governor. Reported-and-tested-by: Tim Gardner <tim.gardner@canonical.com> Signed-off-by: Jacob Shin <jacob.shin@amd.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9e895ac commit c283755

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

drivers/cpufreq/cpufreq_ondemand.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static struct od_ops od_ops;
4747
static struct cpufreq_governor cpufreq_gov_ondemand;
4848
#endif
4949

50+
static unsigned int default_powersave_bias;
51+
5052
static void ondemand_powersave_bias_init_cpu(int cpu)
5153
{
5254
struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
@@ -543,7 +545,7 @@ static int od_init(struct dbs_data *dbs_data)
543545

544546
tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
545547
tuners->ignore_nice = 0;
546-
tuners->powersave_bias = 0;
548+
tuners->powersave_bias = default_powersave_bias;
547549
tuners->io_is_busy = should_io_be_busy();
548550

549551
dbs_data->tuners = tuners;
@@ -585,6 +587,7 @@ static void od_set_powersave_bias(unsigned int powersave_bias)
585587
unsigned int cpu;
586588
cpumask_t done;
587589

590+
default_powersave_bias = powersave_bias;
588591
cpumask_clear(&done);
589592

590593
get_online_cpus();
@@ -593,11 +596,17 @@ static void od_set_powersave_bias(unsigned int powersave_bias)
593596
continue;
594597

595598
policy = per_cpu(od_cpu_dbs_info, cpu).cdbs.cur_policy;
596-
dbs_data = policy->governor_data;
597-
od_tuners = dbs_data->tuners;
598-
od_tuners->powersave_bias = powersave_bias;
599+
if (!policy)
600+
continue;
599601

600602
cpumask_or(&done, &done, policy->cpus);
603+
604+
if (policy->governor != &cpufreq_gov_ondemand)
605+
continue;
606+
607+
dbs_data = policy->governor_data;
608+
od_tuners = dbs_data->tuners;
609+
od_tuners->powersave_bias = default_powersave_bias;
601610
}
602611
put_online_cpus();
603612
}

0 commit comments

Comments
 (0)