From: Xunlei Pang <xlpang@126.com>
To: linux-kernel@vger.kernel.org, Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
linux-pm@vger.kernel.org, Xunlei Pang <pang.xunlei@linaro.org>
Subject: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index
Date: Tue, 4 Aug 2015 13:48:57 +0800 [thread overview]
Message-ID: <1438667337-16903-3-git-send-email-xlpang@126.com> (raw)
In-Reply-To: <1438667337-16903-1-git-send-email-xlpang@126.com>
From: Xunlei Pang <pang.xunlei@linaro.org>
Since we're using cpuidle_driver::safe_state_index directly as the
target state index, it's better to add the sanity check at the point
of registering the driver.
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
drivers/cpuidle/driver.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 5db1478..def299e 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -223,10 +223,23 @@ static void poll_idle_init(struct cpuidle_driver *drv) {}
static int __cpuidle_register_driver(struct cpuidle_driver *drv)
{
int ret;
+#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
+ int i;
+#endif
if (!drv || !drv->state_count)
return -EINVAL;
+#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
+ 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;
+ }
+#endif
+
if (cpuidle_disabled())
return -ENODEV;
--
1.9.1
next prev parent reply other threads:[~2015-08-04 5:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-04 5:48 [PATCH v2 1/3] cpuidle/coupled: Remove cpuidle_device::safe_state_index Xunlei Pang
2015-08-04 5:48 ` [PATCH v2 2/3] cpuidle/coupled: Remove redundant 'dev' argument of cpuidle_state_is_coupled() Xunlei Pang
2015-08-04 5:48 ` Xunlei Pang [this message]
2015-08-28 14:04 ` [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index Rafael J. Wysocki
2015-08-25 14:29 ` [PATCH v2 1/3] cpuidle/coupled: Remove cpuidle_device::safe_state_index pang.xunlei
2015-08-28 14:01 ` 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=1438667337-16903-3-git-send-email-xlpang@126.com \
--to=xlpang@126.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pang.xunlei@linaro.org \
--cc=rjw@rjwysocki.net \
/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
all inboxes | Powered by JetHome®