cpufreq: scmi: Avoid overflow of target_freq in fast switch
authorJagadeesh Kona <quic_jkona@quicinc.com>
Mon, 20 May 2024 06:37:32 +0000 (12:07 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Tue, 28 May 2024 04:01:09 +0000 (09:31 +0530)
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>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/cpufreq/scmi-cpufreq.c

index 3b4f6bfb2f4cf3ee2184948d2b991e3d5f196153..b87fd127aa43306affea8deed862b9c8a11357d3 100644 (file)
@@ -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;