cpufreq: exit() callback is optional
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 12 Apr 2024 05:49:20 +0000 (11:19 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 12 Apr 2024 11:37:00 +0000 (13:37 +0200)
The exit() callback is optional and shouldn't be called without checking
a valid pointer first.

Also, we must clear freq_table pointer even if the exit() callback isn't
present.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Fixes: 91a12e91dc39 ("cpufreq: Allow light-weight tear down and bring up of CPUs")
Fixes: f339f3541701 ("cpufreq: Rearrange locking in cpufreq_remove_dev()")
Reported-by: Lizhe <sensor1010@163.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 66e10a19d76abc3476282c69060c0cac4a815084..fd9c3ed21f49c4d3b9e10e0679078cff385253d2 100644 (file)
@@ -1679,10 +1679,13 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
         */
        if (cpufreq_driver->offline) {
                cpufreq_driver->offline(policy);
-       } else if (cpufreq_driver->exit) {
-               cpufreq_driver->exit(policy);
-               policy->freq_table = NULL;
+               return;
        }
+
+       if (cpufreq_driver->exit)
+               cpufreq_driver->exit(policy);
+
+       policy->freq_table = NULL;
 }
 
 static int cpufreq_offline(unsigned int cpu)
@@ -1740,7 +1743,7 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
        }
 
        /* We did light-weight exit earlier, do full tear down now */
-       if (cpufreq_driver->offline)
+       if (cpufreq_driver->offline && cpufreq_driver->exit)
                cpufreq_driver->exit(policy);
 
        up_write(&policy->rwsem);