[PATCH v3 1/6] cpufreq: Export acpu_cpufreq_exit for other drivers to call

From: Mario Limonciello
Date: Thu Apr 14 2022 - 13:03:58 EST


Currently, the only way to load an alternative cpufreq driver is to unload
acpi-cpufreq first.

Loosen that restriction to allow other kernel modules to unregister a
registered driver.

Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
---
v2->v3:
* Move to include header
* Create a new symbol to prevent NX protected page fault calling exit
function from other modules.
v1->v2:
* Export symbol instead of changing internals

drivers/cpufreq/acpi-cpufreq.c | 10 ++++++++--
include/linux/cpufreq.h | 3 +++
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 3d514b82d055..38358ed1f932 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -1033,7 +1033,7 @@ static int __init acpi_cpufreq_init(void)
return ret;
}

-static void __exit acpi_cpufreq_exit(void)
+void acpi_cpufreq_exit(void)
{
pr_debug("%s\n", __func__);

@@ -1043,6 +1043,12 @@ static void __exit acpi_cpufreq_exit(void)

free_acpi_perf_data();
}
+EXPORT_SYMBOL_GPL(acpi_cpufreq_exit);
+
+void __exit acpi_cpufreq_module_exit(void)
+{
+ acpi_cpufreq_exit();
+}

module_param(acpi_pstate_strict, uint, 0644);
MODULE_PARM_DESC(acpi_pstate_strict,
@@ -1050,7 +1056,7 @@ MODULE_PARM_DESC(acpi_pstate_strict,
"performed during frequency changes.");

late_initcall(acpi_cpufreq_init);
-module_exit(acpi_cpufreq_exit);
+module_exit(acpi_cpufreq_module_exit);

static const struct x86_cpu_id __maybe_unused acpi_cpufreq_ids[] = {
X86_MATCH_FEATURE(X86_FEATURE_ACPI, NULL),
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 35c7d6db4139..223bf9760117 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -273,6 +273,9 @@ static inline void cpufreq_stats_record_transition(struct cpufreq_policy *policy
unsigned int new_freq) { }
#endif /* CONFIG_CPU_FREQ_STAT */

+#if defined(CONFIG_X86_ACPI_CPUFREQ) || defined(CONFIG_X86_ACPI_CPUFREQ_MODULE)
+void acpi_cpufreq_exit(void);
+#endif
/*********************************************************************
* CPUFREQ DRIVER INTERFACE *
*********************************************************************/
--
2.34.1