From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Xunlei Pang <xlpang@126.com>
Cc: linux-kernel@vger.kernel.org,
Daniel Lezcano <daniel.lezcano@linaro.org>,
linux-pm@vger.kernel.org, Xunlei Pang <pang.xunlei@linaro.org>
Subject: Re: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index
Date: Fri, 28 Aug 2015 16:04:56 +0200 [thread overview]
Message-ID: <1492539.aTp0xzx2ya@vostro.rjw.lan> (raw)
In-Reply-To: <1438667337-16903-3-git-send-email-xlpang@126.com>
On Tuesday, August 04, 2015 01:48:57 PM Xunlei Pang wrote:
> 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
Please move this code to a separate function depending on
CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED, define a "return 0" stub of it for
CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED unset and call it from here.
Generally, please try to avoid using #ifdef and similar in function bodies
if possible.
> +
> if (cpuidle_disabled())
> return -ENODEV;
>
>
Thanks,
Rafael
next prev parent reply other threads:[~2015-08-28 13:37 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 ` [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index Xunlei Pang
2015-08-28 14:04 ` Rafael J. Wysocki [this message]
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=1492539.aTp0xzx2ya@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pang.xunlei@linaro.org \
--cc=xlpang@126.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
all inboxes | Powered by JetHome®