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

Commit fe492f3f authored by Viresh Kumar's avatar Viresh Kumar Committed by Rafael J. Wysocki
Browse files

cpufreq: Fix broken usage of governor->owner's refcount



The cpufreq governor owner refcount usage is broken.  We should only
increment that refcount when a CPUFREQ_GOV_POLICY_INIT event has come
and it should only be decremented if CPUFREQ_GOV_POLICY_EXIT has come.

Currently, there can be situations where the governor is in use, but
we have allowed it to be unloaded which may result in undefined
behavior.  Let's fix it.

Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent eb608521
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1709,6 +1709,7 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
		}
	}

	if (event == CPUFREQ_GOV_POLICY_INIT)
		if (!try_module_get(policy->governor->owner))
			return -EINVAL;

@@ -1719,6 +1720,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
	if ((!policy->governor_enabled && (event == CPUFREQ_GOV_STOP)) ||
	    (policy->governor_enabled && (event == CPUFREQ_GOV_START))) {
		mutex_unlock(&cpufreq_governor_lock);
		if (event == CPUFREQ_GOV_POLICY_INIT)
			module_put(policy->governor->owner);
		return -EBUSY;
	}

@@ -1746,11 +1749,8 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
		mutex_unlock(&cpufreq_governor_lock);
	}

	/* we keep one module reference alive for
			each CPU governed by this CPU */
	if ((event != CPUFREQ_GOV_START) || ret)
		module_put(policy->governor->owner);
	if ((event == CPUFREQ_GOV_STOP) && !ret)
	if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
			((event == CPUFREQ_GOV_POLICY_EXIT) && !ret))
		module_put(policy->governor->owner);

	return ret;