Re: [PATCH 4.4 092/134] cpufreq: Fix governor module removal race

From: Ben Hutchings
Date: Sun Apr 01 2018 - 16:56:51 EST


On Mon, 2018-03-19 at 19:06 +0100, Greg Kroah-Hartman wrote:
> 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
>
> ------------------
>
> From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
>
>
> [ Upstream commit a8b149d32b663c1a4105273295184b78f53d33cf ]
[...]
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -551,6 +551,8 @@ static int cpufreq_parse_governor(char *
> Â *governor = t;
> Â err = 0;
> Â }
> + if (t && !try_module_get(t->owner))
> + t = NULL;

This won't work because t is dead after this point. ÂThe fix appears to
depend on:

commit 045149e6a22119e5bf0d16a0b24a4173a2abb71d
Author: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Date: Thu Nov 23 01:23:16 2017 +0100

cpufreq: Clean up cpufreq_parse_governor()

which moves the assignment to *governor further down.

Ben.
Â
> Â mutex_unlock(&cpufreq_governor_mutex);
> Â }
> @@ -669,6 +671,10 @@ static ssize_t store_scaling_governor(st
> Â return -EINVAL;
> Â
> Â ret = cpufreq_set_policy(policy, &new_policy);
> +
> + if (new_policy.governor)
> + module_put(new_policy.governor->owner);
> +
> Â return ret ? ret : count;
> Â}
> Â

--
Ben Hutchings
Software Developer, Codethink Ltd.