From: Viresh Kumar <viresh.kumar@linaro.org>
To: rjw@sisk.pl
Cc: linaro-kernel@lists.linaro.org, patches@linaro.org,
cpufreq@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com,
Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH V2 11/11] cpufreq: improve error checking on return values of __cpufreq_governor()
Date: Tue, 6 Aug 2013 22:53:13 +0530 [thread overview]
Message-ID: <16cf42ac264fc8d0e7604807b01ae796ad6a77c0.1375809311.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1375809311.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1375809311.git.viresh.kumar@linaro.org>
__cpufreq_governor() function can fail in rare cases specially if there are bugs
in cpufreq driver. And so we must stop processing as soon as this routine fails,
otherwise it may result in undefined behavior.
And so this patch adds error checking code whenever this routine is called from
any place.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 48 +++++++++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index ccaf025..06f8671 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,
int ret = 0, has_target = !!cpufreq_driver->target;
unsigned long flags;
- if (has_target)
- __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ if (has_target) {
+ ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ if (ret) {
+ pr_err("%s: Failed to stop governor\n", __func__);
+ return ret;
+ }
+ }
lock_policy_rwsem_write(policy->cpu);
@@ -889,8 +894,11 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
unlock_policy_rwsem_write(policy->cpu);
if (has_target) {
- __cpufreq_governor(policy, CPUFREQ_GOV_START);
- __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
+ (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
+ pr_err("%s: Failed to start governor\n", __func__);
+ return ret;
+ }
}
/* Don't touch sysfs links during light-weight init */
@@ -1171,7 +1179,7 @@ static int __cpufreq_remove_dev(struct device *dev,
struct subsys_interface *sif, bool frozen)
{
unsigned int cpu = dev->id, cpus;
- int new_cpu;
+ int new_cpu, ret;
unsigned long flags;
struct cpufreq_policy *policy;
struct kobject *kobj;
@@ -1195,8 +1203,13 @@ static int __cpufreq_remove_dev(struct device *dev,
return -EINVAL;
}
- if (cpufreq_driver->target)
- __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ if (cpufreq_driver->target) {
+ ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ if (ret) {
+ pr_err("%s: Failed to stop governor\n", __func__);
+ return ret;
+ }
+ }
#ifdef CONFIG_HOTPLUG_CPU
if (!cpufreq_driver->setpolicy)
@@ -1230,8 +1243,15 @@ static int __cpufreq_remove_dev(struct device *dev,
/* If cpu is last user of policy, free policy */
if (cpus == 1) {
- if (cpufreq_driver->target)
- __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
+ if (cpufreq_driver->target) {
+ ret = __cpufreq_governor(policy,
+ CPUFREQ_GOV_POLICY_EXIT);
+ if (ret) {
+ pr_err("%s: Failed to exit governor\n",
+ __func__);
+ return ret;
+ }
+ }
if (!frozen) {
lock_policy_rwsem_read(cpu);
@@ -1262,8 +1282,12 @@ static int __cpufreq_remove_dev(struct device *dev,
cpufreq_policy_free(policy);
} else {
if (cpufreq_driver->target) {
- __cpufreq_governor(policy, CPUFREQ_GOV_START);
- __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
+ (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
+ pr_err("%s: Failed to start governor\n",
+ __func__);
+ return ret;
+ }
}
}
@@ -1911,7 +1935,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *policy,
/* might be a policy change, too, so fall through */
}
pr_debug("governor: change or update limits\n");
- __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
}
error_out:
--
1.7.12.rc2.18.g61b472e
next prev parent reply other threads:[~2013-08-06 17:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-06 17:23 [PATCH V2 00/11] CPUFreq: Fixes & Cleanups for 3.12 Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 01/11] cpufreq: Cleanup header files included in core Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 02/11] cpufreq: Re-arrange declarations in cpufreq.h Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 03/11] cpufreq: Give consistent names for struct cpufreq_policy * Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 04/11] cpufreq: Use sizeof(*ptr) form for finding size of a struct Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 05/11] cpufreq: Pass policy to cpufreq_add_policy_cpu() Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 06/11] cpufreq: Store cpufreq policies in a list Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 07/11] cpufreq: Use cpufreq_policy_list for iterating over policies Viresh Kumar
2013-08-18 14:06 ` Rafael J. Wysocki
2013-08-19 11:27 ` Viresh Kumar
2013-08-19 11:45 ` Amit Kucheria
2013-08-20 6:32 ` Viresh Kumar
2013-08-19 23:22 ` Rafael J. Wysocki
2013-08-20 6:33 ` Viresh Kumar
2013-08-20 6:35 ` Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 08/11] cpufreq: Fix broken usage of governor->owner's refcount Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 09/11] cpufreq: Don't use cpufreq_driver->owner's refcount to protect critical sections Viresh Kumar
2013-08-06 17:23 ` [PATCH V2 10/11] cpufreq: Remove struct cpufreq_driver's owner field Viresh Kumar
2013-08-06 17:23 ` Viresh Kumar [this message]
2013-08-07 0:21 ` [PATCH V2 00/11] CPUFreq: Fixes & Cleanups for 3.12 Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16cf42ac264fc8d0e7604807b01ae796ad6a77c0.1375809311.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=cpufreq@vger.kernel.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@linaro.org \
--cc=rjw@sisk.pl \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).