diff mbox series

cpufreq: Fix policy initialization for internal governor drivers

Message ID 3873122.F9s1CIEcb3@kreacher (mailing list archive)
State Mainlined, archived
Headers show
Series cpufreq: Fix policy initialization for internal governor drivers | expand

Commit Message

Rafael J. Wysocki Feb. 26, 2020, 9:39 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Before commit 1e4f63aecb53 ("cpufreq: Avoid creating excessively
large stack frames") the initial value of the policy field in struct
cpufreq_policy set by the driver's ->init() callback was implicitly
passed from cpufreq_init_policy() to cpufreq_set_policy() if the
default governor was neither "performance" nor "powersave".  After
that commit, however, cpufreq_init_policy() must take that case into
consideration explicitly and handle it as appropriate, so make that
happen.

Fixes: 1e4f63aecb53 ("cpufreq: Avoid creating excessively large stack frames")
Link: https://lore.kernel.org/linux-pm/39fb762880c27da110086741315ca8b111d781cd.camel@gmail.com/
Reported-by: Artem Bityutskiy <dedekind1@gmail.com>
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

Note that I'm going to fast-track this patch for 5.6-rc4 which means that
it will go into my linux-next branch as soon as it shows up in the lists.

Thanks and sorry for the breakage!

---
 drivers/cpufreq/cpufreq.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Viresh Kumar Feb. 27, 2020, 5:19 a.m. UTC | #1
On 26-02-20, 22:39, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Before commit 1e4f63aecb53 ("cpufreq: Avoid creating excessively
> large stack frames") the initial value of the policy field in struct
> cpufreq_policy set by the driver's ->init() callback was implicitly
> passed from cpufreq_init_policy() to cpufreq_set_policy() if the
> default governor was neither "performance" nor "powersave".  After
> that commit, however, cpufreq_init_policy() must take that case into
> consideration explicitly and handle it as appropriate, so make that
> happen.
> 
> Fixes: 1e4f63aecb53 ("cpufreq: Avoid creating excessively large stack frames")
> Link: https://lore.kernel.org/linux-pm/39fb762880c27da110086741315ca8b111d781cd.camel@gmail.com/
> Reported-by: Artem Bityutskiy <dedekind1@gmail.com>
> Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> Note that I'm going to fast-track this patch for 5.6-rc4 which means that
> it will go into my linux-next branch as soon as it shows up in the lists.
> 
> Thanks and sorry for the breakage!
> 
> ---
>  drivers/cpufreq/cpufreq.c |   14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===================================================================
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -1076,9 +1076,17 @@ static int cpufreq_init_policy(struct cp
>  			pol = policy->last_policy;
>  		} else if (def_gov) {
>  			pol = cpufreq_parse_policy(def_gov->name);
> -		} else {
> -			return -ENODATA;
> +			/*
> +			 * In case the default governor is neiter "performance"
> +			 * nor "powersave", fall back to the initial policy
> +			 * value set by the driver.
> +			 */
> +			if (pol == CPUFREQ_POLICY_UNKNOWN)
> +				pol = policy->policy;
>  		}
> +		if (pol != CPUFREQ_POLICY_PERFORMANCE &&
> +		    pol != CPUFREQ_POLICY_POWERSAVE)
> +			return -ENODATA;
>  	}
>  
>  	return cpufreq_set_policy(policy, gov, pol);

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Artem Bityutskiy Feb. 27, 2020, 8:28 a.m. UTC | #2
On Wed, 2020-02-26 at 22:39 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Before commit 1e4f63aecb53 ("cpufreq: Avoid creating excessively
> large stack frames") the initial value of the policy field in struct
> cpufreq_policy set by the driver's ->init() callback was implicitly
> passed from cpufreq_init_policy() to cpufreq_set_policy() if the
> default governor was neither "performance" nor "powersave".  After
> that commit, however, cpufreq_init_policy() must take that case into
> consideration explicitly and handle it as appropriate, so make that
> happen.
> 
> Fixes: 1e4f63aecb53 ("cpufreq: Avoid creating excessively large stack frames")
> Link: https://lore.kernel.org/linux-pm/39fb762880c27da110086741315ca8b111d781cd.camel@gmail.com/
> Reported-by: Artem Bityutskiy <dedekind1@gmail.com>
> Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Many thanks, fixes the issue.

Artem.
diff mbox series

Patch

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1076,9 +1076,17 @@  static int cpufreq_init_policy(struct cp
 			pol = policy->last_policy;
 		} else if (def_gov) {
 			pol = cpufreq_parse_policy(def_gov->name);
-		} else {
-			return -ENODATA;
+			/*
+			 * In case the default governor is neiter "performance"
+			 * nor "powersave", fall back to the initial policy
+			 * value set by the driver.
+			 */
+			if (pol == CPUFREQ_POLICY_UNKNOWN)
+				pol = policy->policy;
 		}
+		if (pol != CPUFREQ_POLICY_PERFORMANCE &&
+		    pol != CPUFREQ_POLICY_POWERSAVE)
+			return -ENODATA;
 	}
 
 	return cpufreq_set_policy(policy, gov, pol);