[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<CYYPR12MB865557345D178854A02609059C942@CYYPR12MB8655.namprd12.prod.outlook.com>
Date: Tue, 27 Aug 2024 06:06:47 +0000
From: "Yuan, Perry" <Perry.Yuan@....com>
To: Anastasia Belova <abelova@...ralinux.ru>, "Huang, Ray" <Ray.Huang@....com>
CC: "Shenoy, Gautham Ranjal" <gautham.shenoy@....com>, "Limonciello, Mario"
<Mario.Limonciello@....com>, "Rafael J. Wysocki" <rafael@...nel.org>, Viresh
Kumar <viresh.kumar@...aro.org>, "linux-pm@...r.kernel.org"
<linux-pm@...r.kernel.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "lvc-project@...uxtesting.org"
<lvc-project@...uxtesting.org>
Subject: RE: [PATCH v2] cpufreq: amd-pstate: add check for cpufreq_cpu_get's
return value
[AMD Official Use Only - AMD Internal Distribution Only]
> -----Original Message-----
> From: Anastasia Belova <abelova@...ralinux.ru>
> Sent: Monday, August 26, 2024 9:39 PM
> To: Huang, Ray <Ray.Huang@....com>
> Cc: Anastasia Belova <abelova@...ralinux.ru>; Shenoy, Gautham Ranjal
> <gautham.shenoy@....com>; Limonciello, Mario
> <Mario.Limonciello@....com>; Yuan, Perry <Perry.Yuan@....com>; Rafael J.
> Wysocki <rafael@...nel.org>; Viresh Kumar <viresh.kumar@...aro.org>; linux-
> pm@...r.kernel.org; linux-kernel@...r.kernel.org; lvc-
> project@...uxtesting.org
> Subject: [PATCH v2] cpufreq: amd-pstate: add check for cpufreq_cpu_get's
> return value
>
> 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>
> ---
> v2: remove mixing code and declarations
> drivers/cpufreq/amd-pstate.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 68c616b572f2..f8d474168430 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -656,7 +656,12 @@ static void amd_pstate_adjust_perf(unsigned int
> cpu,
> unsigned long max_perf, min_perf, des_perf,
> cap_perf, lowest_nonlinear_perf;
> struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> - struct amd_cpudata *cpudata = policy->driver_data;
> + struct amd_cpudata *cpudata;
> +
> + if (!policy)
> + return;
> +
> + cpudata = policy->driver_data;
>
> if (policy->min != cpudata->min_limit_freq || policy->max != cpudata-
> >max_limit_freq)
> amd_pstate_update_min_max_limit(policy);
> @@ -870,11 +875,16 @@ static void amd_pstate_init_prefcore(struct
> amd_cpudata *cpudata) static void amd_pstate_update_limits(unsigned int
> cpu) {
> struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> - struct amd_cpudata *cpudata = policy->driver_data;
> + struct amd_cpudata *cpudata;
> u32 prev_high = 0, cur_high = 0;
> int ret;
> bool highest_perf_changed = false;
>
> + if (!policy)
> + return;
> +
> + cpudata = policy->driver_data;
> +
> mutex_lock(&amd_pstate_driver_lock);
> if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
> goto free_cpufreq_put;
> --
> 2.30.2
Thanks for the fix, LGTM,
Reviewed-by: Perry Yuan <perry.yuan@....com>
Best Regards.
Perry.
Powered by blists - more mailing lists