From a7615aebabc680800f4922350719a7f6c059f841 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 11 May 2004 14:59:02 +0100 Subject: [PATCH] [CPUFREQ] Fix for longrun.c for degenerate case From H. Peter Anvin I ran into a system the other day which had a Transmeta processor, but configured in a degenerate, fixed-frequency configuration. It crashed booting Fedora Core 2 test 3 due to a division by zero in the longrun cpufreq driver. --- arch/i386/kernel/cpu/cpufreq/longrun.c | 28 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/i386/kernel/cpu/cpufreq/longrun.c b/arch/i386/kernel/cpu/cpufreq/longrun.c index 5e4dacf938ced..c04c99bba8c97 100644 --- a/arch/i386/kernel/cpu/cpufreq/longrun.c +++ b/arch/i386/kernel/cpu/cpufreq/longrun.c @@ -46,11 +46,16 @@ static void __init longrun_get_policy(struct cpufreq_policy *policy) rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); msr_lo &= 0x0000007F; msr_hi &= 0x0000007F; - - policy->min = longrun_low_freq + msr_lo * - ((longrun_high_freq - longrun_low_freq) / 100); - policy->max = longrun_low_freq + msr_hi * - ((longrun_high_freq - longrun_low_freq) / 100); + + if ( longrun_high_freq <= longrun_low_freq ) { + /* Assume degenerate Longrun table */ + policy->min = policy->max = longrun_high_freq; + } else { + policy->min = longrun_low_freq + msr_lo * + ((longrun_high_freq - longrun_low_freq) / 100); + policy->max = longrun_low_freq + msr_hi * + ((longrun_high_freq - longrun_low_freq) / 100); + } policy->cpu = 0; } @@ -70,10 +75,15 @@ static int longrun_set_policy(struct cpufreq_policy *policy) if (!policy) return -EINVAL; - pctg_lo = (policy->min - longrun_low_freq) / - ((longrun_high_freq - longrun_low_freq) / 100); - pctg_hi = (policy->max - longrun_low_freq) / - ((longrun_high_freq - longrun_low_freq) / 100); + if ( longrun_high_freq <= longrun_low_freq ) { + /* Assume degenerate Longrun table */ + pctg_lo = pctg_hi = 100; + } else { + pctg_lo = (policy->min - longrun_low_freq) / + ((longrun_high_freq - longrun_low_freq) / 100); + pctg_hi = (policy->max - longrun_low_freq) / + ((longrun_high_freq - longrun_low_freq) / 100); + } if (pctg_hi > 100) pctg_hi = 100; -- 2.53.0