sched: ems: avoid to access empty energy table
authorPark Bumgyu <bumgyu.park@samsung.com>
Thu, 5 Apr 2018 05:36:40 +0000 (14:36 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:35:31 +0000 (17:35 +0900)
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 <bumgyu.park@samsung.com>
kernel/sched/ems/core.c

index 26f2e65f800bdec44e514ad35607fe767f3bd3cf..b24d3f76db63062cc71be8538eecd2d8ad0b83aa 100644 (file)
@@ -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))