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


Groups > linux.kernel > #1553988 > unrolled thread

[PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement.

Started byChris Lapa <chris@lapa.com.au>
First post2017-01-09 01:50 +0100
Last post2017-01-09 16:40 +0100
Articles 2 — 2 participants

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

  [PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement. Chris Lapa <chris@lapa.com.au> - 2017-01-09 01:50 +0100
    Re: [PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to  a switch statement. "Andrew F. Davis" <afd@ti.com> - 2017-01-09 16:40 +0100

#1553988 — [PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement.

FromChris Lapa <chris@lapa.com.au>
Date2017-01-09 01:50 +0100
Subject[PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement.
Message-ID<sXwjT-5mL-7@gated-at.bofh.it>
From: Chris Lapa <chris@lapa.com.au>

This is done for readability as the upcoming commits will add a lot of
cases.

tested: no

Signed-off-by: Chris Lapa <chris@lapa.com.au>
---
 drivers/power/supply/bq27xxx_battery.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 3b0dbc6..fd4cc4e 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -635,12 +635,17 @@ static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di)
  */
 static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)
 {
-	if (di->chip == BQ27500 || di->chip == BQ27541 || di->chip == BQ27545)
+	switch (di->chip) {
+	case BQ27500:
+	case BQ27541:
+	case BQ27545:
 		return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);
-	if (di->chip == BQ27530 || di->chip == BQ27421)
+	case BQ27530:
+	case BQ27421:
 		return flags & BQ27XXX_FLAG_OT;
-
-	return false;
+	default:
+		return false;
+	}
 }
 
 /*
-- 
2.1.4

[toc] | [next] | [standalone]


#1554422 — Re: [PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement.

From"Andrew F. Davis" <afd@ti.com>
Date2017-01-09 16:40 +0100
SubjectRe: [PATCH v3 01/11] power: supplies: bq275xx: move overtemp tests to a switch statement.
Message-ID<sXKdb-5VJ-17@gated-at.bofh.it>
In reply to#1553988
On 01/08/2017 06:47 PM, Chris Lapa wrote:
> From: Chris Lapa <chris@lapa.com.au>
> 
> This is done for readability as the upcoming commits will add a lot of
> cases.
> 
> tested: no
> 
> Signed-off-by: Chris Lapa <chris@lapa.com.au>
> ---
>  drivers/power/supply/bq27xxx_battery.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
> index 3b0dbc6..fd4cc4e 100644
> --- a/drivers/power/supply/bq27xxx_battery.c
> +++ b/drivers/power/supply/bq27xxx_battery.c
> @@ -635,12 +635,17 @@ static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di)
>   */
>  static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)
>  {
> -	if (di->chip == BQ27500 || di->chip == BQ27541 || di->chip == BQ27545)
> +	switch (di->chip) {
> +	case BQ27500:
> +	case BQ27541:
> +	case BQ27545:

As some functions are not long enough to need this refactoring, I feel
we still have some code consistency issues in this driver. At some point
it may be better to add some additional fields to the device definition
structure, then we reference that and not use coded cases for selection.

For now, this and the rest of the series look correct to me:

Reviewed-by: Andrew F. Davis <afd@ti.com>

>  		return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);
> -	if (di->chip == BQ27530 || di->chip == BQ27421)
> +	case BQ27530:
> +	case BQ27421:
>  		return flags & BQ27XXX_FLAG_OT;
> -
> -	return false;
> +	default:
> +		return false;
> +	}
>  }
>  
>  /*
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web