Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4632f561 authored by Joonwoo Park's avatar Joonwoo Park
Browse files

sched: prevent out of bound access in sched_group_energy()



group_idle_state() can return INT_MAX + 1 which is undefined behaviour
when there is no CPUs in sched_group.  Prevent such by error correctly.

Change-Id: I236a90b9725edc2f394ade6533368f5d4b1a21d2
Signed-off-by: default avatarJoonwoo Park <joonwoop@codeaurora.org>
parent 1fd6e206
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -5553,6 +5553,9 @@ static int group_idle_state(struct sched_group *sg)
	for_each_cpu(i, sched_group_cpus(sg))
		state = min(state, idle_get_state_idx(cpu_rq(i)));

	if (unlikely(state == INT_MAX))
		return -EINVAL;

	/* Take non-cpuidle idling into account (active idle/arch_cpu_idle()) */
	state++;

@@ -5638,6 +5641,9 @@ static int sched_group_energy(struct energy_env *eenv)
				}

				idle_idx = group_idle_state(sg);
				if (unlikely(idle_idx < 0))
					return idle_idx;

				group_util = group_norm_util(eenv, sg);
				sg_busy_energy = (group_util * sg->sge->cap_states[cap_idx].power);