]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpufreq: exit() callback is optional
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 12 Apr 2024 05:49:20 +0000 (11:19 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 May 2024 07:49:11 +0000 (09:49 +0200)
[ Upstream commit b8f85833c05730d631576008daaa34096bc7f3ce ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/cpufreq/cpufreq.c

index 3c2c955fbbbd69a67745cfa929faee6ed61da31d..86f1bc7754ea6c1b2ea3e724bc0728b5c37bc8bc 100644 (file)
@@ -1670,10 +1670,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)
@@ -1731,7 +1734,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);