aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
authorSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>2013-07-29 18:54:11 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-07 17:02:48 -0400
commite9698cc5d2749c5b74e137f94a95d7e505b097e8 (patch)
tree2687d73dd78e85412cec1104b2d6630e987ef921 /drivers/cpufreq/cpufreq.c
parent23d328994b548d6822b88fe7e1903652afc354e0 (diff)
cpufreq: Add helper to perform alloc/free of policy structure
Separate out the allocation of the cpufreq policy structure (along with its error handling) to a helper function. This makes the code easier to read and also helps with some upcoming code reorganization. Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r--drivers/cpufreq/cpufreq.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 5b317b0db902..18e58c1bfd66 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -944,6 +944,37 @@ static int cpufreq_add_policy_cpu(unsigned int cpu, unsigned int sibling,
944} 944}
945#endif 945#endif
946 946
947static struct cpufreq_policy *cpufreq_policy_alloc(void)
948{
949 struct cpufreq_policy *policy;
950
951 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
952 if (!policy)
953 return NULL;
954
955 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
956 goto err_free_policy;
957
958 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
959 goto err_free_cpumask;
960
961 return policy;
962
963err_free_cpumask:
964 free_cpumask_var(policy->cpus);
965err_free_policy:
966 kfree(policy);
967
968 return NULL;
969}
970
971static void cpufreq_policy_free(struct cpufreq_policy *policy)
972{
973 free_cpumask_var(policy->related_cpus);
974 free_cpumask_var(policy->cpus);
975 kfree(policy);
976}
977
947/** 978/**
948 * cpufreq_add_dev - add a CPU device 979 * cpufreq_add_dev - add a CPU device
949 * 980 *
@@ -997,16 +1028,10 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
997 goto module_out; 1028 goto module_out;
998 } 1029 }
999 1030
1000 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL); 1031 policy = cpufreq_policy_alloc();
1001 if (!policy) 1032 if (!policy)
1002 goto nomem_out; 1033 goto nomem_out;
1003 1034
1004 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1005 goto err_free_policy;
1006
1007 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1008 goto err_free_cpumask;
1009
1010 policy->cpu = cpu; 1035 policy->cpu = cpu;
1011 policy->governor = CPUFREQ_DEFAULT_GOVERNOR; 1036 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1012 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1037 cpumask_copy(policy->cpus, cpumask_of(cpu));
@@ -1071,11 +1096,7 @@ err_out_unregister:
1071 1096
1072err_set_policy_cpu: 1097err_set_policy_cpu:
1073 per_cpu(cpufreq_policy_cpu, cpu) = -1; 1098 per_cpu(cpufreq_policy_cpu, cpu) = -1;
1074 free_cpumask_var(policy->related_cpus); 1099 cpufreq_policy_free(policy);
1075err_free_cpumask:
1076 free_cpumask_var(policy->cpus);
1077err_free_policy:
1078 kfree(policy);
1079nomem_out: 1100nomem_out:
1080 module_put(cpufreq_driver->owner); 1101 module_put(cpufreq_driver->owner);
1081module_out: 1102module_out:
@@ -1199,9 +1220,7 @@ static int __cpufreq_remove_dev(struct device *dev,
1199 if (cpufreq_driver->exit) 1220 if (cpufreq_driver->exit)
1200 cpufreq_driver->exit(data); 1221 cpufreq_driver->exit(data);
1201 1222
1202 free_cpumask_var(data->related_cpus); 1223 cpufreq_policy_free(data);
1203 free_cpumask_var(data->cpus);
1204 kfree(data);
1205 } else { 1224 } else {
1206 pr_debug("%s: removing link, cpu: %d\n", __func__, cpu); 1225 pr_debug("%s: removing link, cpu: %d\n", __func__, cpu);
1207 cpufreq_cpu_put(data); 1226 cpufreq_cpu_put(data);