From: Park Bumgyu Date: Thu, 5 Apr 2018 05:36:40 +0000 (+0900) Subject: sched: ems: avoid to access empty energy table X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0b010e6e5f5dacdcc1d67f7adee38f5f8a7cdf6e;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git sched: ems: avoid to access empty energy table Accessing the energy table without allocation cause a NULL pointer exception. energy_table.nr_states have values after the energy table created, so check the nr_states to avoid problem. Change-Id: I90d6c9b8ff5ac0eb67b92ab0bb57b911d8f65091 Signed-off-by: Park Bumgyu --- diff --git a/kernel/sched/ems/core.c b/kernel/sched/ems/core.c index 26f2e65f800b..b24d3f76db63 100644 --- a/kernel/sched/ems/core.c +++ b/kernel/sched/ems/core.c @@ -32,6 +32,13 @@ static int cpu_util_wake(int cpu, struct task_struct *p) return (util >= capacity) ? capacity : util; } +struct energy_table { + struct capacity_state *states; + unsigned int nr_states; +}; + +DEFINE_PER_CPU(struct energy_table, energy_table); + struct eco_env { struct task_struct *p; @@ -51,6 +58,13 @@ static void find_eco_target(struct eco_env *eenv) int backup_cpu = -1; int cpu; + /* + * It is meaningless to find an energy cpu when the energy table is + * not created or has not been created yet. + */ + if (!per_cpu(energy_table, eenv->prev_cpu).nr_states) + return; + rcu_read_lock(); for_each_cpu_and(cpu, &p->cpus_allowed, cpu_active_mask) { @@ -125,13 +139,6 @@ static void find_eco_target(struct eco_env *eenv) eenv->backup_cpu = backup_cpu; } -struct energy_table { - struct capacity_state *states; - unsigned int nr_states; -}; - -DEFINE_PER_CPU(struct energy_table, energy_table); - static unsigned int calculate_energy(struct task_struct *p, int target_cpu) { unsigned long util[NR_CPUS] = {0, }; @@ -274,6 +281,8 @@ select_energy_cpu(struct task_struct *p, int prev_cpu, int sd_flag, int sync) struct eco_env eenv = { .p = p, .prev_cpu = prev_cpu, + .best_cpu = -1, + .backup_cpu = -1, }; if (!sched_feat(ENERGY_AWARE))