Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1215338 > unrolled thread

Re: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index

Started by"Rafael J. Wysocki" <rjw@rjwysocki.net>
First post2015-08-28 15:40 +0200
Last post2015-08-28 15:40 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2015-08-28 15:40 +0200

#1215338 — Re: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index

From"Rafael J. Wysocki" <rjw@rjwysocki.net>
Date2015-08-28 15:40 +0200
SubjectRe: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index
Message-ID<q2s2T-4H9-31@gated-at.bofh.it>
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web