public inbox for arm-scmi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: scmi: Fix possible null pointer dereference
@ 2025-04-12 18:08 Chenyuan Yang
  2025-04-12 18:30 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Chenyuan Yang @ 2025-04-12 18:08 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar
  Cc: arm-scmi, linux-arm-kernel, linux-pm, linux-kernel, Chenyuan Yang

Check if policy is NULL before dereferencing it.

This is similar to the commit cf7de25878a1
("cppc_cpufreq: Fix possible null pointer dereference").

This is found by our static analysis tool KNighter.

Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Fixes: 99d6bdf33877 ("cpufreq: add support for CPU DVFS based on SCMI message protocol")
---
 drivers/cpufreq/scmi-cpufreq.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index c310aeebc8f3..ee916ce9b897 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -38,10 +38,14 @@ static struct cpufreq_driver scmi_cpufreq_driver;
 static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
-	struct scmi_data *priv = policy->driver_data;
+	struct scmi_data *priv;
 	unsigned long rate;
 	int ret;
 
+	if (!policy)
+		return 0;
+	priv = policy->driver_data;
+
 	ret = perf_ops->freq_get(ph, priv->domain_id, &rate, false);
 	if (ret)
 		return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: scmi: Fix possible null pointer dereference
  2025-04-12 18:08 [PATCH] cpufreq: scmi: Fix possible null pointer dereference Chenyuan Yang
@ 2025-04-12 18:30 ` Dan Carpenter
  2025-04-12 18:32   ` Chenyuan Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2025-04-12 18:30 UTC (permalink / raw)
  To: Chenyuan Yang
  Cc: sudeep.holla, cristian.marussi, rafael, viresh.kumar, arm-scmi,
	linux-arm-kernel, linux-pm, linux-kernel

On Sat, Apr 12, 2025 at 01:08:31PM -0500, Chenyuan Yang wrote:
> Check if policy is NULL before dereferencing it.
> 
> This is similar to the commit cf7de25878a1
> ("cppc_cpufreq: Fix possible null pointer dereference").
> 
> This is found by our static analysis tool KNighter.
> 
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 99d6bdf33877 ("cpufreq: add support for CPU DVFS based on SCMI message protocol")

Henry Martin already fixed this in commit 484d3f15cc6c ("cpufreq: scmi:
Fix null-ptr-deref in scmi_cpufreq_get_rate()").

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: scmi: Fix possible null pointer dereference
  2025-04-12 18:30 ` Dan Carpenter
@ 2025-04-12 18:32   ` Chenyuan Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Chenyuan Yang @ 2025-04-12 18:32 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: sudeep.holla, cristian.marussi, rafael, viresh.kumar, arm-scmi,
	linux-arm-kernel, linux-pm, linux-kernel

On Sat, Apr 12, 2025 at 1:31 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> On Sat, Apr 12, 2025 at 01:08:31PM -0500, Chenyuan Yang wrote:
> > Check if policy is NULL before dereferencing it.
> >
> > This is similar to the commit cf7de25878a1
> > ("cppc_cpufreq: Fix possible null pointer dereference").
> >
> > This is found by our static analysis tool KNighter.
> >
> > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> > Fixes: 99d6bdf33877 ("cpufreq: add support for CPU DVFS based on SCMI message protocol")
>
> Henry Martin already fixed this in commit 484d3f15cc6c ("cpufreq: scmi:
> Fix null-ptr-deref in scmi_cpufreq_get_rate()").

Thanks so much for pointing this out!
It is good to hear that there is already a fix.

> regards,
> dan carpenter

-Chenyuan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-12 18:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-12 18:08 [PATCH] cpufreq: scmi: Fix possible null pointer dereference Chenyuan Yang
2025-04-12 18:30 ` Dan Carpenter
2025-04-12 18:32   ` Chenyuan Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox