Skip to contentSkip to conversation

cpufreq: error path fixes

PATCH In review Jan Beulich 2 participants 2 messages Oct 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: error path fixes

This fixes an actual bug (failure to exit from a function after an allocation failure), an inconsistency (not removing the cpufreq_dom list member upon failure), and a latent bug (not clearing the current governor upon governor initialization failure when there was no old one; latent because the only current code path leading to this situation frees the policy upon failure and hence the governor not getting cleared is benign).

xen/drivers/cpufreq/cpufreq.c +5 -3
@@ -176,8 +176,10 @@ int cpufreq_add_cpu(unsigned int cpu)
 
     if (!domexist || hw_all) {
         policy = xzalloc(struct cpufreq_policy);
-        if (!policy)
+        if (!policy) {
             ret = -ENOMEM;
+            goto err0;
+        }
 
         policy->cpu = cpu;
         per_cpu(cpufreq_cpu_policy, cpu) = policy;
@@ -186,7 +188,7 @@ int cpufreq_add_cpu(unsigned int cpu)
         if (ret) {
             xfree(policy);
             per_cpu(cpufreq_cpu_policy, cpu) = NULL;
-            return ret;
+            goto err0;
         }
         if (cpufreq_verbose)
             printk("CPU %u initialization completed\n", cpu);
@@ -243,7 +245,7 @@ err1:
         cpufreq_driver->exit(policy);
         xfree(policy);
     }
-
+err0:
     if (cpus_empty(cpufreq_dom->map)) {
         list_del(&cpufreq_dom->node);
         xfree(cpufreq_dom);
xen/drivers/cpufreq/utility.c +1 -1
@@ -458,8 +458,8 @@ int __cpufreq_set_policy(struct cpufreq_
                                  data->governor->name);
 
             /* new governor failed, so re-start old one */
+            data->governor = old_gov;
             if (old_gov) {
-                data->governor = old_gov;
                 __cpufreq_governor(data, CPUFREQ_GOV_START);
                 printk(KERN_WARNING "Still stay at %s governor\n",
                                      data->governor->name);
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jan Beulich

This fixes an actual bug (failure to exit from a function after an allocation failure), an inconsistency (not removing the cpufreq_dom list member upon failure), and a latent bug (not clearing the current governor upon governor initialization failure when there was no old one; latent because the only current code path leading to this situation frees the policy upon failure and hence the governor not getting cleared is benign).

Quoted 52 lines
xen/drivers/cpufreq/cpufreq.c +5 -3
@@ -176,8 +176,10 @@ int cpufreq_add_cpu(unsigned int cpu)
 
     if (!domexist || hw_all) {
         policy = xzalloc(struct cpufreq_policy);
-        if (!policy)
+        if (!policy) {
             ret = -ENOMEM;
+            goto err0;
+        }
 
         policy->cpu = cpu;
         per_cpu(cpufreq_cpu_policy, cpu) = policy;
@@ -186,7 +188,7 @@ int cpufreq_add_cpu(unsigned int cpu)
         if (ret) {
             xfree(policy);
             per_cpu(cpufreq_cpu_policy, cpu) = NULL;
-            return ret;
+            goto err0;
         }
         if (cpufreq_verbose)
             printk("CPU %u initialization completed\n", cpu);
@@ -243,7 +245,7 @@ err1:
         cpufreq_driver->exit(policy);
         xfree(policy);
     }
-
+err0:
     if (cpus_empty(cpufreq_dom->map)) {
         list_del(&cpufreq_dom->node);
         xfree(cpufreq_dom);
xen/drivers/cpufreq/utility.c +1 -1
@@ -458,8 +458,8 @@ int __cpufreq_set_policy(struct cpufreq_
                                  data->governor->name);
 
             /* new governor failed, so re-start old one */
+            data->governor = old_gov;
             if (old_gov) {
-                data->governor = old_gov;
                 __cpufreq_governor(data, CPUFREQ_GOV_START);
                 printk(KERN_WARNING "Still stay at %s governor\n",
                                      data->governor->name);

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