Skip to contentSkip to conversation

x86/cpufreq: check array index before use

PATCH New Jan Beulich 1 participant 1 message Jul 6, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpufreq: check array index before use

... rather than after.

xen/arch/x86/acpi/cpufreq/cpufreq.c +4 -2
@@ -210,9 +210,11 @@ static u32 get_cur_val(cpumask_t mask)
 
     if (!cpu_isset(cpu, mask))
         cpu = first_cpu(mask);
-    policy = cpufreq_cpu_policy[cpu];
+    if (cpu >= NR_CPUS)
+        return 0;
 
-    if (cpu >= NR_CPUS || !policy || !drv_data[policy->cpu])
+    policy = cpufreq_cpu_policy[cpu];
+    if (!policy || !drv_data[policy->cpu])
         return 0;    
 
     switch (drv_data[policy->cpu]->cpu_feature) {

... rather than after.

xen/arch/x86/acpi/cpufreq/cpufreq.c +4 -2
@@ -210,9 +210,11 @@ static u32 get_cur_val(cpumask_t mask)
 
     if (!cpu_isset(cpu, mask))
         cpu = first_cpu(mask);
-    policy = cpufreq_cpu_policy[cpu];
+    if (cpu >= NR_CPUS)
+        return 0;
 
-    if (cpu >= NR_CPUS || !policy || !drv_data[policy->cpu])
+    policy = cpufreq_cpu_policy[cpu];
+    if (!policy || !drv_data[policy->cpu])
         return 0;    
 
     switch (drv_data[policy->cpu]->cpu_feature) {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel