diff mbox series

[v2] cpufreq: Make cpufreq_online() call driver->offline() on errors

Message ID 5490292.DvuYhMxLoT@kreacher
State New
Headers show
Series [v2] cpufreq: Make cpufreq_online() call driver->offline() on errors | expand

Commit Message

Rafael J. Wysocki June 22, 2021, 7:11 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH] cpufreq: Make cpufreq_online() call driver->offline() on errors

In the CPU removal path the ->offline() callback provided by the
driver is always invoked before ->exit(), but in the cpufreq_online()
error path it is not, so ->exit() is expected to somehow know the
context in which it has been called and act accordingly.

That is less than straightforward, so make cpufreq_online() invoke
the driver's ->offline() callback, if present, on errors before
->exit() too.

This only potentially affects intel_pstate.

Fixes: 91a12e91dc39 ("cpufreq: Allow light-weight tear down and bring up of CPUs")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

-> v2:
   * Avoid calling ->offline() after a failing ->online().
   * Add a comment regarding the expected state after calling ->init().
   * Edit the changelog a bit.

---
 drivers/cpufreq/cpufreq.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Viresh Kumar June 23, 2021, 3:10 a.m. UTC | #1
On 22-06-21, 21:11, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Subject: [PATCH] cpufreq: Make cpufreq_online() call driver->offline() on errors
> 
> In the CPU removal path the ->offline() callback provided by the
> driver is always invoked before ->exit(), but in the cpufreq_online()
> error path it is not, so ->exit() is expected to somehow know the
> context in which it has been called and act accordingly.
> 
> That is less than straightforward, so make cpufreq_online() invoke
> the driver's ->offline() callback, if present, on errors before
> ->exit() too.
> 
> This only potentially affects intel_pstate.
> 
> Fixes: 91a12e91dc39 ("cpufreq: Allow light-weight tear down and bring up of CPUs")
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> -> v2:
>    * Avoid calling ->offline() after a failing ->online().
>    * Add a comment regarding the expected state after calling ->init().
>    * Edit the changelog a bit.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
diff mbox series

Patch

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1367,9 +1367,14 @@  static int cpufreq_online(unsigned int c
 			goto out_free_policy;
 		}
 
+		/*
+		 * The initialization has succeeded and the policy is online.
+		 * If there is a problem with its frequency table, take it
+		 * offline and drop it.
+		 */
 		ret = cpufreq_table_validate_and_sort(policy);
 		if (ret)
-			goto out_exit_policy;
+			goto out_offline_policy;
 
 		/* related_cpus should at least include policy->cpus. */
 		cpumask_copy(policy->related_cpus, policy->cpus);
@@ -1515,6 +1520,10 @@  out_destroy_policy:
 
 	up_write(&policy->rwsem);
 
+out_offline_policy:
+	if (cpufreq_driver->offline)
+		cpufreq_driver->offline(policy);
+
 out_exit_policy:
 	if (cpufreq_driver->exit)
 		cpufreq_driver->exit(policy);