[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241211101520.2105475-1-jianqi.ren.cn@windriver.com>
Date: Wed, 11 Dec 2024 18:15:20 +0800
From: <jianqi.ren.cn@...driver.com>
To: <abelova@...ralinux.ru>, <gregkh@...uxfoundation.org>
CC: <patches@...ts.linux.dev>, <viresh.kumar@...aro.org>, <perry.yuan@....com>,
<stable@...r.kernel.org>, <ray.huang@....com>, <rafael@...nel.org>,
<linux-pm@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH 6.1.y] cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value
From: Anastasia Belova <abelova@...ralinux.ru>
[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]
cpufreq_cpu_get may return NULL. To avoid NULL-dereference check it
and return in case of error.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Anastasia Belova <abelova@...ralinux.ru>
Reviewed-by: Perry Yuan <perry.yuan@....com>
Signed-off-by: Viresh Kumar <viresh.kumar@...aro.org>
Signed-off-by: Jianqi Ren <jianqi.ren.cn@...driver.com>
---
drivers/cpufreq/amd-pstate.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 90dcf26f0973..106aef210003 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -309,9 +309,14 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
unsigned long max_perf, min_perf, des_perf,
cap_perf, lowest_nonlinear_perf, max_freq;
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
- struct amd_cpudata *cpudata = policy->driver_data;
+ struct amd_cpudata *cpudata;
unsigned int target_freq;
+ if (!policy)
+ return;
+
+ cpudata = policy->driver_data;
+
cap_perf = READ_ONCE(cpudata->highest_perf);
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
max_freq = READ_ONCE(cpudata->max_freq);
--
2.25.1
Powered by blists - more mailing lists