diff mbox series

[v2] cpufreq: apple-soc: Prevent null pointer dereference in apple_soc_cpufreq_get_rate()

Message ID 20241230091053.247719-1-hanchunchao@inspur.com (mailing list archive)
State New
Headers show
Series [v2] cpufreq: apple-soc: Prevent null pointer dereference in apple_soc_cpufreq_get_rate() | expand

Commit Message

Charles Han Dec. 30, 2024, 9:10 a.m. UTC
cpufreq_cpu_get_raw() may return NULL if the cpu is not in
policy->cpus cpu mask and it will cause null pointer dereference.
Prevent null pointer dereference in apple_soc_cpufreq_get_rate().

Fixes: 6286bbb40576 ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/cpufreq/apple-soc-cpufreq.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Markus Elfring Dec. 30, 2024, 12:12 p.m. UTC | #1
> cpufreq_cpu_get_raw() may return NULL if the cpu is not in
> policy->cpus cpu mask and it will cause null pointer dereference.
> Prevent null pointer dereference in apple_soc_cpufreq_get_rate().> ---
>  drivers/cpufreq/apple-soc-cpufreq.c | 3 +++
>  1 file changed, 3 insertions(+)
It can be helpful to provide a corresponding patch version description.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13-rc5#n310

Regards,
Markus
diff mbox series

Patch

diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c
index 4dcacab9b4bf..1c6d81355b41 100644
--- a/drivers/cpufreq/apple-soc-cpufreq.c
+++ b/drivers/cpufreq/apple-soc-cpufreq.c
@@ -104,6 +104,9 @@  static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = {
 static unsigned int apple_soc_cpufreq_get_rate(unsigned int cpu)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
+	if (unlikely(!policy))
+		return 0;
+
 	struct apple_cpu_priv *priv = policy->driver_data;
 	struct cpufreq_frequency_table *p;
 	unsigned int pstate;