From 37c2f83262b7859c3b61a659a3d453fba58aeb86 Mon Sep 17 00:00:00 2001 From: Huang Cun Date: Tue, 18 Jun 2024 17:22:27 +0800 Subject: [PATCH] cpufreq: CPPC: Add support for frequency invariance's divide-by zero part fix ampere cpu kernel warning: cpufreg: cpufreg_online: ->get() failed refer upstream 1eb5dde674f57 (cpufreq: CPPC: Add support for frequency invariance) backport this commit's divide-by zero part Signed-off-by: Huang Cun --- drivers/cpufreq/cppc_cpufreq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 900a65156af9..d07d38e9faed 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -382,12 +382,12 @@ static int cppc_get_rate_from_fbctrs(struct cppc_cpudata *cpu, delta_delivered = get_delta(fb_ctrs_t1.delivered, fb_ctrs_t0.delivered); - /* Check to avoid divide-by zero */ - if (delta_reference || delta_delivered) + /* Check to avoid divide-by zero and invalid delivered_perf */ + if (!delta_reference || !delta_delivered) + delivered_perf = cpu->perf_ctrls.desired_perf; + else delivered_perf = (reference_perf * delta_delivered) / delta_reference; - else - delivered_perf = cpu->perf_ctrls.desired_perf; return cppc_cpufreq_perf_to_khz(cpu, delivered_perf); }