diff mbox

[v2,1/5] slw: Simplify if-condition while adding idle states to device tree

Message ID 1462258628-6827-2-git-send-email-shreyas@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Shreyas B. Prabhu May 3, 2016, 6:57 a.m. UTC
if-condition in add_cpu_idle_state_properties which checks if a given idle
state is supported  is bloated with multiple  '&' and '||' operations.
Simplify by adding a mask variable and setting the relevant bits.
This patch does not change any functionality.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
---
 hw/slw.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Michael Neuling June 2, 2016, 6:52 a.m. UTC | #1
On Tue, 2016-05-03 at 12:27 +0530, Shreyas B. Prabhu wrote:
> if-condition in add_cpu_idle_state_properties which checks if a given
> idle
> state is supported  is bloated with multiple  '&' and '||' operations.
> Simplify by adding a mask variable and setting the relevant bits.
> This patch does not change any functionality.
> 
> Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>

Acked-by: Michael Neuling <mikey@neuling.org>

> ---
>  hw/slw.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/slw.c b/hw/slw.c
> index b67097c97ddd..231fefcd0b58 100644
> --- a/hw/slw.c
> +++ b/hw/slw.c
> @@ -500,6 +500,8 @@ void add_cpu_idle_state_properties(void)
>  	bool can_sleep = true, can_winkle = true;
>  	u8 i;
>  
> +	u32 supported_states_mask;
> +
>  	/* Buffers to hold idle state properties */
>  	char *name_buf, *alloced_name_buf;
>  	u32 *latency_ns_buf;
> @@ -589,12 +591,21 @@ void add_cpu_idle_state_properties(void)
>  	name_buf_len = 0;
>  	num_supported_idle_states = 0;
>  
> +	/*
> +	 * Create a mask with the flags of all supported idle states
> +	 * set. Use this to only add supported idle states to the
> +	 * device-tree
> +	 */
> +	supported_states_mask = OPAL_PM_NAP_ENABLED;
> +	if (can_sleep)
> +		supported_states_mask |= OPAL_PM_SLEEP_ENABLED |
> +					OPAL_PM_SLEEP_ENABLED_ER1;
> +	if (can_winkle)
> +		supported_states_mask |= OPAL_PM_WINKLE_ENABLED;
> +
>  	for (i = 0; i < nr_states; i++) {
>  		/* For each state, check if it is one of the supported
> states. */
> -		if( (states[i].flags & OPAL_PM_NAP_ENABLED) ||
> -		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED) &&
> can_sleep) ||
> -		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED_ER1) &&
> can_sleep) ||
> -		   ((states[i].flags & OPAL_PM_WINKLE_ENABLED) &&
> can_winkle) ) {
> +		if (states[i].flags & supported_states_mask) {
>  			/*
>  			 * If a state is supported add each of its
> property
>  			 * to its corresponding property buffer.
diff mbox

Patch

diff --git a/hw/slw.c b/hw/slw.c
index b67097c97ddd..231fefcd0b58 100644
--- a/hw/slw.c
+++ b/hw/slw.c
@@ -500,6 +500,8 @@  void add_cpu_idle_state_properties(void)
 	bool can_sleep = true, can_winkle = true;
 	u8 i;
 
+	u32 supported_states_mask;
+
 	/* Buffers to hold idle state properties */
 	char *name_buf, *alloced_name_buf;
 	u32 *latency_ns_buf;
@@ -589,12 +591,21 @@  void add_cpu_idle_state_properties(void)
 	name_buf_len = 0;
 	num_supported_idle_states = 0;
 
+	/*
+	 * Create a mask with the flags of all supported idle states
+	 * set. Use this to only add supported idle states to the
+	 * device-tree
+	 */
+	supported_states_mask = OPAL_PM_NAP_ENABLED;
+	if (can_sleep)
+		supported_states_mask |= OPAL_PM_SLEEP_ENABLED |
+					OPAL_PM_SLEEP_ENABLED_ER1;
+	if (can_winkle)
+		supported_states_mask |= OPAL_PM_WINKLE_ENABLED;
+
 	for (i = 0; i < nr_states; i++) {
 		/* For each state, check if it is one of the supported states. */
-		if( (states[i].flags & OPAL_PM_NAP_ENABLED) ||
-		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED) && can_sleep) ||
-		   ((states[i].flags & OPAL_PM_SLEEP_ENABLED_ER1) && can_sleep) ||
-		   ((states[i].flags & OPAL_PM_WINKLE_ENABLED) && can_winkle) ) {
+		if (states[i].flags & supported_states_mask) {
 			/*
 			 * If a state is supported add each of its property
 			 * to its corresponding property buffer.