Răsfoiți Sursa

cpufreq: intel_pstate: Avoid division by 0 in min_perf_pct_min()

Commit c5a2ee7dde89 (cpufreq: intel_pstate: Active mode P-state
limits rework) incorrectly assumed that pstate.turbo_pstate would
always be nonzero for CPU0 in min_perf_pct_min() if
cpufreq_register_driver() had succeeded which may not be the case
in virtualized environments.

If that assumption doesn't hold, it leads to an early crash on boot
in intel_pstate_register_driver(), so add a sanity check to
min_perf_pct_min() to prevent the crash from happening.

Fixes: c5a2ee7dde89 (cpufreq: intel_pstate: Active mode P-state limits rework)
Reported-and-tested-by: Jongman Heo <jongman.heo@samsung.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Rafael J. Wysocki 8 ani în urmă
părinte
comite
57caf4ec2b
1 a modificat fișierele cu 3 adăugiri și 2 ștergeri
  1. 3 2
      drivers/cpufreq/intel_pstate.c

+ 3 - 2
drivers/cpufreq/intel_pstate.c

@@ -571,9 +571,10 @@ static inline void update_turbo_state(void)
 static int min_perf_pct_min(void)
 static int min_perf_pct_min(void)
 {
 {
 	struct cpudata *cpu = all_cpu_data[0];
 	struct cpudata *cpu = all_cpu_data[0];
+	int turbo_pstate = cpu->pstate.turbo_pstate;
 
 
-	return DIV_ROUND_UP(cpu->pstate.min_pstate * 100,
-			    cpu->pstate.turbo_pstate);
+	return turbo_pstate ?
+		DIV_ROUND_UP(cpu->pstate.min_pstate * 100, turbo_pstate) : 0;
 }
 }
 
 
 static s16 intel_pstate_get_epb(struct cpudata *cpu_data)
 static s16 intel_pstate_get_epb(struct cpudata *cpu_data)