summaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/coupled.c
diff options
context:
space:
mode:
authorXunlei Pang <pang.xunlei@linaro.org>2015-08-31 11:34:05 +0800
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-09-03 03:05:47 +0200
commitabceaa9cded5f059f8c3b3b6f32730084fe5e39f (patch)
tree8f4cfa6f48e5ed6b6eee71ba4d2b7c334a705ba9 /drivers/cpuidle/coupled.c
parent4c1ed5a6079078699128064664913ae7b079648f (diff)
downloadlinux-abceaa9cded5f059f8c3b3b6f32730084fe5e39f.tar.gz
linux-abceaa9cded5f059f8c3b3b6f32730084fe5e39f.tar.bz2
linux-abceaa9cded5f059f8c3b3b6f32730084fe5e39f.zip
cpuidle/coupled: Add sanity check for safe_state_index
Since we are using cpuidle_driver::safe_state_index directly as the target state index, it is better to add the sanity check at the point of registering the driver. Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpuidle/coupled.c')
-rw-r--r--drivers/cpuidle/coupled.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/cpuidle/coupled.c b/drivers/cpuidle/coupled.c
index 1523e2d745eb..344058f8501a 100644
--- a/drivers/cpuidle/coupled.c
+++ b/drivers/cpuidle/coupled.c
@@ -187,6 +187,28 @@ bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state)
}
/**
+ * cpuidle_coupled_state_verify - check if the coupled states are correctly set.
+ * @drv: struct cpuidle_driver for the platform
+ *
+ * Returns 0 for valid state values, a negative error code otherwise:
+ * * -EINVAL if any coupled state(safe_state_index) is wrongly set.
+ */
+int cpuidle_coupled_state_verify(struct cpuidle_driver *drv)
+{
+ int i;
+
+ for (i = drv->state_count - 1; i >= 0; i--) {
+ if (cpuidle_state_is_coupled(drv, i) &&
+ (drv->safe_state_index == i ||
+ drv->safe_state_index < 0 ||
+ drv->safe_state_index >= drv->state_count))
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/**
* cpuidle_coupled_set_ready - mark a cpu as ready
* @coupled: the struct coupled that contains the current cpu
*/