2024-05-17 07:02:55

by Jagadeesh Kona

[permalink] [raw]
Subject: [PATCH] cpufreq: scmi: Avoid overflow of target_freq in fast switch

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 u64 variable for converting
it to HZ.

Signed-off-by: Jagadeesh Kona <[email protected]>
---
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..42be87aebe6f 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;
+ u64 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



2024-05-20 05:27:21

by Jagadeesh Kona

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: scmi: Avoid overflow of target_freq in fast switch



On 5/17/2024 12:31 PM, Jagadeesh Kona wrote:
> 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 u64 variable for converting
> it to HZ.
>
> Signed-off-by: Jagadeesh Kona <[email protected]>
> ---
> 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..42be87aebe6f 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;
> + u64 freq = target_freq;
>

To keep type of freq consistent with the rate parameter of scmi
freq_set() callback which is unsigned long, will move the above freq
variable from u64 to unsigned long and post the v2 series.

Thanks,
Jagadeesh

> - 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;