Fix for longrun.c for degenerate case
Hi all,
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. The attached patch fixes this.
-hpa
Index: linux-2.5/arch/i386/kernel/cpu/cpufreq/longrun.c
===================================================================
RCS file: /home/hpa/kernel/bkcvs/linux-2.5/arch/i386/kernel/cpu/cpufreq/longrun.c,v retrieving revision 1.19
arch/i386/kernel/cpu/cpufreq/longrun.c +19 -9
@@ -46,11 +46,16 @@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 @@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 ;
_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq
Quoted 6 lines · H. Peter Anvin
Hi all,
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. The attached patch fixes this.
Thanks. I'd suggest that driver initialization should fail instead -- there's no reason to keep the cpufreq infrastructure up and running if nothing at all can be done, e.g. the frequency is fixed. The attached patch (untested due to lack of hardware) should do right that. Dave, please decide which patch you prefer, and merge accordingly.
Thanks,
Dominik
arch/i386/kernel/cpu/cpufreq/longrun.c +3 -0
@@ -239,6 +239,9 @@if (result)return result; +if (longrun_high_freq <= longrun_low_freq) +return -ENODEV ;/* degenerate Longrun table */ +/* cpuinfo and default policy values */ policy->cpuinfo.min_freq = longrun_low_freq; policy->cpuinfo.max_freq = longrun_high_freq;