From: Wyes Karny <wyes.karny@amd.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Huang Rui <ray.huang@amd.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Perry Yuan <Perry.Yuan@amd.com>,
Mario Limonciello <Mario.Limonciello@amd.com>,
Arnd Bergmann <arnd@arndb.de>, Jinzhou Su <Jinzhou.Su@amd.com>,
Meng Li <li.meng@amd.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use
Date: Wed, 8 Feb 2023 14:28:24 +0000 [thread overview]
Message-ID: <Y+OxiFNRsL39t3tW@beas> (raw)
In-Reply-To: <20230207161256.271613-1-arnd@kernel.org>
On 07 Feb 17:12, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The new epp support causes warnings about three separate
> but related bugs:
>
> 1) failing before allocation should just return an error:
>
> drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (!dev)
> ^~~~
> drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here
> return ret;
> ^~~
>
> 2) wrong variable to store return code:
>
> drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (rc)
> ^~
> drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here
> return ret;
> ^~~
> drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false
> if (rc)
> ^~~~~~~
>
> 3) calling amd_pstate_set_epp() in cleanup path after determining
> that it should not be called:
>
> drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (cpudata->epp_policy == cpudata->policy)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here
> amd_pstate_set_epp(cpudata, epp);
> ^~~
>
> All three are trivial to fix, but most likely there are additional bugs
> in this function when the error handling was not really tested.
>
> Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/cpufreq/amd-pstate.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 168a28bed6ee..847f5f31396d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
> struct amd_cpudata *cpudata;
> struct device *dev;
> - int rc;
> u64 value;
>
> /*
> @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> amd_perf_ctl_reset(policy->cpu);
> dev = get_cpu_device(policy->cpu);
> if (!dev)
> - goto free_cpudata1;
> + return -ENODEV;
>
> cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL);
> if (!cpudata)
> @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> cpudata->cpu = policy->cpu;
> cpudata->epp_policy = 0;
>
> - rc = amd_pstate_init_perf(cpudata);
> - if (rc)
> + ret = amd_pstate_init_perf(cpudata);
> + if (ret)
> goto free_cpudata1;
>
> min_freq = amd_get_min_freq(cpudata);
> @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu)
> value |= (u64)epp << 24;
> }
>
> + amd_pstate_set_epp(cpudata, epp);
> skip_epp:
> WRITE_ONCE(cpudata->cppc_req_cached, value);
> - amd_pstate_set_epp(cpudata, epp);
> cpufreq_cpu_put(policy);
> }
>
Tested this on AMD Milan (Zen 3) system.
Tested-by: Wyes Karny <wyes.karny@amd.com>
> --
> 2.39.1
>
next prev parent reply other threads:[~2023-02-08 14:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 16:12 [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use Arnd Bergmann
2023-02-08 14:28 ` Wyes Karny [this message]
2023-02-09 2:02 ` Yuan, Perry
2023-02-09 5:03 ` Huang Rui
2023-02-09 19:22 ` Rafael J. Wysocki
2023-02-09 9:58 ` Wyes Karny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y+OxiFNRsL39t3tW@beas \
--to=wyes.karny@amd.com \
--cc=Jinzhou.Su@amd.com \
--cc=Mario.Limonciello@amd.com \
--cc=Perry.Yuan@amd.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=li.meng@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox