mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] cpufreq: scmi: Avoid overflow of target_freq in fast switch
@ 2024-05-20  6:37 Jagadeesh Kona
  2024-05-20  8:47 ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Jagadeesh Kona @ 2024-05-20  6:37 UTC (permalink / raw)
  To: Sudeep Holla, Viresh Kumar, Rafael J . Wysocki, Cristian Marussi
  Cc: linux-arm-kernel, linux-pm, linux-kernel, Taniya Das,
	Ajit Pandey, Imran Shaik, Vivek Aknurwar, Mike Tipton,
	Jagadeesh Kona

Conversion of target_freq to HZ in scmi_cpufreq_fast_switch()
can lead to overflow if the multiplied result is greater than
UINT_MAX, since type of target_freq is unsigned int. Avoid this
overflow by assigning target_freq to unsigned long variable for
converting it to HZ.

Signed-off-by: Jagadeesh Kona <quic_jkona@quicinc.com>
---
Changes in V2:
  - Updated freq variable from u64 to unsigned long to keep it
    consistent with the rate parameter in scmi .freq_set() callback
  - Link to v1: https://lore.kernel.org/all/20240517070157.19553-1-quic_jkona@quicinc.com/
---
 drivers/cpufreq/scmi-cpufreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 3b4f6bfb2f4c..b87fd127aa43 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -63,9 +63,9 @@ static unsigned int scmi_cpufreq_fast_switch(struct cpufreq_policy *policy,
 					     unsigned int target_freq)
 {
 	struct scmi_data *priv = policy->driver_data;
+	unsigned long freq = target_freq;
 
-	if (!perf_ops->freq_set(ph, priv->domain_id,
-				target_freq * 1000, true))
+	if (!perf_ops->freq_set(ph, priv->domain_id, freq * 1000, true))
 		return target_freq;
 
 	return 0;
-- 
2.43.0


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

end of thread, other threads:[~2024-05-31  3:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-20  6:37 [PATCH V2] cpufreq: scmi: Avoid overflow of target_freq in fast switch Jagadeesh Kona
2024-05-20  8:47 ` Viresh Kumar
2024-05-27  9:56   ` Jagadeesh Kona
2024-05-28  4:03     ` Viresh Kumar
2024-05-31  3:20       ` Jagadeesh Kona

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

all inboxes | Powered by JetHome®