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

Commit 997a8de4 authored by Venkateswara Rao Tadikonda's avatar Venkateswara Rao Tadikonda
Browse files

msm: kgsl: Fix a dead loop issue while changing gpu frequency



There is a dead loop in kgsl driver function, while changing governor
frequency. In governor 'userspace' mode, If the requested frequency
(set_freq) is more than the configured frequency and max_freq is also
set to more than the configured frequency, then there is a dead loop
while changing target frequency.

Dead loop occurs due to comparing signed integer 'i' with unsigned integer
'max_pwrlevel'. Decrementing 'i' beyond zero will cause dead loop.
So, change the array index 'i' of pwrlevels[] to unsigned int, which can't
be decremented beyond zero. Also, changing loop condition to restrict 'i'
within permitted levels.

Change-Id: Ic82b7477d50d1abcd348b011f64246066887922c
Signed-off-by: default avatarVenkateswara Rao Tadikonda <vtadik@codeaurora.org>
parent 4d9a308b
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -530,7 +530,8 @@ int kgsl_devfreq_target(struct device *dev, unsigned long *freq, u32 flags)
	struct kgsl_device *device = dev_get_drvdata(dev);
	struct kgsl_pwrctrl *pwr;
	struct kgsl_pwrlevel *pwr_level;
	int level, i;
	int level;
	unsigned int i;
	unsigned long cur_freq, rec_freq;
	struct dev_pm_opp *opp;

@@ -574,7 +575,12 @@ int kgsl_devfreq_target(struct device *dev, unsigned long *freq, u32 flags)
	/* If the governor recommends a new frequency, update it here */
	if (rec_freq != cur_freq) {
		level = pwr->max_pwrlevel;
		for (i = pwr->min_pwrlevel; i >= pwr->max_pwrlevel; i--)
		/*
		 * Array index of pwrlevels[] should be within the permitted
		 * power levels, i.e., from max_pwrlevel to min_pwrlevel.
		 */
		for (i = pwr->min_pwrlevel; (i >= pwr->max_pwrlevel
					  && i <= pwr->min_pwrlevel); i--)
			if (rec_freq <= pwr->pwrlevels[i].gpu_freq) {
				if (pwr->thermal_cycle == CYCLE_ACTIVE)
					level = _thermal_adjust(pwr, i);