aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2013-08-06 13:23:13 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-08-09 21:24:48 -0400
commit3de9bdeb28638e164d1f0eb38dd68e3f5d2ac95c (patch)
treeefe5c314af79f28840a2a31eb2e2ca992c0258ae /drivers/cpufreq/cpufreq.c
parentadc97d6a735dbb1e94cb4f1bf0b55f258b349941 (diff)
cpufreq: improve error checking on return values of __cpufreq_governor()
The __cpufreq_governor() function can fail in rare cases especially if there are bugs in cpufreq drivers. Thus we must stop processing as soon as this routine fails, otherwise it may result in undefined behavior. This patch adds error checking code whenever this routine is called from any place. Signed-off-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.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index c9bbfeef92e3..37a687467329 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -874,8 +874,13 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
874 int ret = 0, has_target = !!cpufreq_driver->target; 874 int ret = 0, has_target = !!cpufreq_driver->target;
875 unsigned long flags; 875 unsigned long flags;
876 876
877 if (has_target) 877 if (has_target) {
878 __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 878 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
879 if (ret) {
880 pr_err("%s: Failed to stop governor\n", __func__);
881 return ret;
882 }
883 }
879 884
880 lock_policy_rwsem_write(policy->cpu); 885 lock_policy_rwsem_write(policy->cpu);
881 886
@@ -889,8 +894,11 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
889 unlock_policy_rwsem_write(policy->cpu); 894 unlock_policy_rwsem_write(policy->cpu);
890 895
891 if (has_target) { 896 if (has_target) {
892 __cpufreq_governor(policy, CPUFREQ_GOV_START); 897 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
893 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 898 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
899 pr_err("%s: Failed to start governor\n", __func__);
900 return ret;
901 }
894 } 902 }
895 903
896 /* Don't touch sysfs links during light-weight init */ 904 /* Don't touch sysfs links during light-weight init */
@@ -1172,7 +1180,7 @@ static int __cpufreq_remove_dev(struct device *dev,
1172 struct subsys_interface *sif, bool frozen) 1180 struct subsys_interface *sif, bool frozen)
1173{ 1181{
1174 unsigned int cpu = dev->id, cpus; 1182 unsigned int cpu = dev->id, cpus;
1175 int new_cpu; 1183 int new_cpu, ret;
1176 unsigned long flags; 1184 unsigned long flags;
1177 struct cpufreq_policy *policy; 1185 struct cpufreq_policy *policy;
1178 struct kobject *kobj; 1186 struct kobject *kobj;
@@ -1196,8 +1204,13 @@ static int __cpufreq_remove_dev(struct device *dev,
1196 return -EINVAL; 1204 return -EINVAL;
1197 } 1205 }
1198 1206
1199 if (cpufreq_driver->target) 1207 if (cpufreq_driver->target) {
1200 __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 1208 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1209 if (ret) {
1210 pr_err("%s: Failed to stop governor\n", __func__);
1211 return ret;
1212 }
1213 }
1201 1214
1202#ifdef CONFIG_HOTPLUG_CPU 1215#ifdef CONFIG_HOTPLUG_CPU
1203 if (!cpufreq_driver->setpolicy) 1216 if (!cpufreq_driver->setpolicy)
@@ -1231,8 +1244,15 @@ static int __cpufreq_remove_dev(struct device *dev,
1231 1244
1232 /* If cpu is last user of policy, free policy */ 1245 /* If cpu is last user of policy, free policy */
1233 if (cpus == 1) { 1246 if (cpus == 1) {
1234 if (cpufreq_driver->target) 1247 if (cpufreq_driver->target) {
1235 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 1248 ret = __cpufreq_governor(policy,
1249 CPUFREQ_GOV_POLICY_EXIT);
1250 if (ret) {
1251 pr_err("%s: Failed to exit governor\n",
1252 __func__);
1253 return ret;
1254 }
1255 }
1236 1256
1237 if (!frozen) { 1257 if (!frozen) {
1238 lock_policy_rwsem_read(cpu); 1258 lock_policy_rwsem_read(cpu);
@@ -1263,8 +1283,12 @@ static int __cpufreq_remove_dev(struct device *dev,
1263 cpufreq_policy_free(policy); 1283 cpufreq_policy_free(policy);
1264 } else { 1284 } else {
1265 if (cpufreq_driver->target) { 1285 if (cpufreq_driver->target) {
1266 __cpufreq_governor(policy, CPUFREQ_GOV_START); 1286 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
1267 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 1287 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
1288 pr_err("%s: Failed to start governor\n",
1289 __func__);
1290 return ret;
1291 }
1268 } 1292 }
1269 } 1293 }
1270 1294
@@ -1912,7 +1936,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *policy,
1912 /* might be a policy change, too, so fall through */ 1936 /* might be a policy change, too, so fall through */
1913 } 1937 }
1914 pr_debug("governor: change or update limits\n"); 1938 pr_debug("governor: change or update limits\n");
1915 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 1939 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1916 } 1940 }
1917 1941
1918error_out: 1942error_out: