Re: [PATCH V3 1/3] cpufreq: Fix locking issues with governors
From: Quentin Perret
Date: Mon Jun 29 2020 - 17:03:09 EST
On Monday 29 Jun 2020 at 07:43:09 (+0530), Viresh Kumar wrote:
> I described why I chose to keep it that way in the other email, but I
> am all for dropping the variable. And so what about this ?
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e798a1193bdf..d9e9ae7051bb 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1064,18 +1064,17 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
> struct cpufreq_governor *def_gov = cpufreq_default_governor();
> struct cpufreq_governor *gov = NULL;
> unsigned int pol = CPUFREQ_POLICY_UNKNOWN;
> - bool put_governor = false;
> int ret;
>
> if (has_target()) {
> /* Update policy governor to the one used before hotplug. */
> gov = get_governor(policy->last_governor);
> if (gov) {
> - put_governor = true;
> pr_debug("Restoring governor %s for cpu %d\n",
> policy->governor->name, policy->cpu);
> } else if (def_gov) {
> gov = def_gov;
> + module_get(gov->owner);
> } else {
> return -ENODATA;
> }
> @@ -1099,7 +1098,7 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
> }
>
> ret = cpufreq_set_policy(policy, gov, pol);
> - if (put_governor)
> + if (gov)
> module_put(gov->owner);
>
> return ret;
Right, I guess this is a good trade-off, so that works for me.
Thanks,
Quentin