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

Commit c87bf20f authored by Satya Durga Srinivasu Prabhala's avatar Satya Durga Srinivasu Prabhala
Browse files

sched: prevent out of bound access in calc_sg_energy



Half-baked change was ported earlier with 'commit 575464db
("sched: prevent out of bound access in sched_group_energy()")'.
Complete the change by bringing in missed changes, update
return value of the function and checks as necessary.

Change-Id: If9796c829c091e461231569dc38c5e5456f58037
Signed-off-by: default avatarSatya Durga Srinivasu Prabhala <satyap@codeaurora.org>
parent c0c89b3b
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -5892,7 +5892,7 @@ static void store_energy_calc_debug_info(struct energy_env *eenv, int cpu_idx, i
 * This works in iterations to compute the SG's energy for each CPU
 * candidate defined by the energy_env's cpu array.
 */
static void calc_sg_energy(struct energy_env *eenv)
static int calc_sg_energy(struct energy_env *eenv)
{
	struct sched_group *sg = eenv->sg;
	unsigned long busy_energy, idle_energy;
@@ -5914,6 +5914,9 @@ static void calc_sg_energy(struct energy_env *eenv)

		/* Compute IDLE energy */
		idle_idx = group_idle_state(eenv, cpu_idx);
		if (unlikely(idle_idx < 0))
			return idle_idx;

		idle_power = sg->sge->idle_states[idle_idx].power;
		idle_energy   = SCHED_CAPACITY_SCALE - sg_util;
		idle_energy  *= idle_power;
@@ -5923,6 +5926,8 @@ static void calc_sg_energy(struct energy_env *eenv)

		store_energy_calc_debug_info(eenv, cpu_idx, cap_idx, idle_idx);
	}

	return 0;
}

/*
@@ -5985,7 +5990,8 @@ static int compute_energy(struct energy_env *eenv)
				 * CPUs in the current visited SG.
				 */
				eenv->sg = sg;
				calc_sg_energy(eenv);
				if (calc_sg_energy(eenv))
					return -EINVAL;

				/* remove CPUs we have just visited */
				if (!sd->child) {