From: Marc Zyngier <maz@kernel.org>
To: Chenyuan Yang <chenyuan0y@gmail.com>
Cc: sven@svenpeter.dev, j@jannau.net, alyssa@rosenzweig.io,
neal@gompa.dev, rafael@kernel.org, viresh.kumar@linaro.org,
marcan@marcan.st, asahi@lists.linux.dev,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: apple-soc: Fix possible null pointer dereference
Date: Sun, 13 Apr 2025 11:02:27 +0100 [thread overview]
Message-ID: <86bjt0l6q4.wl-maz@kernel.org> (raw)
In-Reply-To: <20250412160518.1824538-1-chenyuan0y@gmail.com>
On Sat, 12 Apr 2025 17:05:18 +0100,
Chenyuan Yang <chenyuan0y@gmail.com> wrote:
>
> Check if policy is NULL before dereferencing it.
>
> This is similar to the commit cf7de25878a1
> ("cppc_cpufreq: Fix possible null pointer dereference").
>
No, it's not similar. The patch you refer to actually introduces bugs
by returning -ENODEV in functions that have an unsigned return type.
> This is found by our static analysis tool KNighter.
I'm surprised that your tool hasn't found the above, because it should
be a pretty easy thing to do.
Irrespective of this, it would be good to describe under which
circumstances this can occur, because I can't see *how* this can
trigger. The policy is directly provided by the core code and provide
its association with a cpu, and is never NULL at the point of init.
And if it can trigger, why only fix this one particular case?
Dereferences of policy are all over the map, and would be just as
wrong.
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 6286bbb40576 ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states")
> ---
> drivers/cpufreq/apple-soc-cpufreq.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c
> index 4994c86feb57..3de9bb2b0f22 100644
> --- a/drivers/cpufreq/apple-soc-cpufreq.c
> +++ b/drivers/cpufreq/apple-soc-cpufreq.c
> @@ -135,10 +135,14 @@ 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);
> - struct apple_cpu_priv *priv = policy->driver_data;
> + struct apple_cpu_priv *priv;
> struct cpufreq_frequency_table *p;
> unsigned int pstate;
>
> + if (!policy)
> + return 0;
> + priv = policy->driver_data;
> +
> if (priv->info->cur_pstate_mask) {
> u32 reg = readl_relaxed(priv->reg_base + APPLE_DVFS_STATUS);
>
So while this is not wrong, I don't think this serves any real
purpose.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-04-13 10:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-12 16:05 [PATCH] cpufreq: apple-soc: Fix possible null pointer dereference Chenyuan Yang
2025-04-13 10:02 ` Marc Zyngier [this message]
2025-04-13 21:31 ` Chenyuan Yang
2025-04-14 6:49 ` Marc Zyngier
2025-04-16 7:34 ` Viresh Kumar
2025-04-16 10:22 ` Marc Zyngier
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=86bjt0l6q4.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=chenyuan0y@gmail.com \
--cc=j@jannau.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=neal@gompa.dev \
--cc=rafael@kernel.org \
--cc=sven@svenpeter.dev \
--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;
as well as URLs for NNTP newsgroup(s).