diff mbox series

[4/6] power: supply: charger-manager: Make code more readable

Message ID 12b1b583c3da503be4ad7bed01e7b07a0a2b2126.1542362262.git.baolin.wang@linaro.org
State Accepted
Commit a53a68cee88a4d892bdfcc793a661ced81cd1f56
Headers show
Series [1/6] power: supply: charger-manager: Remove unused index counting | expand

Commit Message

(Exiting) Baolin Wang Nov. 16, 2018, 11:01 a.m. UTC
Make code more readable.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

---
 drivers/power/supply/charger-manager.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

-- 
1.7.9.5

Comments

Sebastian Reichel Dec. 5, 2018, 8:36 p.m. UTC | #1
Hi,

On Fri, Nov 16, 2018 at 07:01:11PM +0800, Baolin Wang wrote:
> Make code more readable.

> 

> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>

> ---


Thanks, queued.

-- Sebastian

>  drivers/power/supply/charger-manager.c |   14 +++++++-------

>  1 file changed, 7 insertions(+), 7 deletions(-)

> 

> diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c

> index a52bc77..dc0c9a6 100644

> --- a/drivers/power/supply/charger-manager.c

> +++ b/drivers/power/supply/charger-manager.c

> @@ -1520,19 +1520,19 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)

>  	/* chargers */

>  	of_property_read_u32(np, "cm-num-chargers", &num_chgs);

>  	if (num_chgs) {

> +		int i;

> +

>  		/* Allocate empty bin at the tail of array */

>  		desc->psy_charger_stat = devm_kcalloc(dev,

>  						      num_chgs + 1,

>  						      sizeof(char *),

>  						      GFP_KERNEL);

> -		if (desc->psy_charger_stat) {

> -			int i;

> -			for (i = 0; i < num_chgs; i++)

> -				of_property_read_string_index(np, "cm-chargers",

> -						i, &desc->psy_charger_stat[i]);

> -		} else {

> +		if (!desc->psy_charger_stat)

>  			return ERR_PTR(-ENOMEM);

> -		}

> +

> +		for (i = 0; i < num_chgs; i++)

> +			of_property_read_string_index(np, "cm-chargers",

> +						      i, &desc->psy_charger_stat[i]);

>  	}

>  

>  	of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge);

> -- 

> 1.7.9.5

>
diff mbox series

Patch

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index a52bc77..dc0c9a6 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1520,19 +1520,19 @@  static struct charger_desc *of_cm_parse_desc(struct device *dev)
 	/* chargers */
 	of_property_read_u32(np, "cm-num-chargers", &num_chgs);
 	if (num_chgs) {
+		int i;
+
 		/* Allocate empty bin at the tail of array */
 		desc->psy_charger_stat = devm_kcalloc(dev,
 						      num_chgs + 1,
 						      sizeof(char *),
 						      GFP_KERNEL);
-		if (desc->psy_charger_stat) {
-			int i;
-			for (i = 0; i < num_chgs; i++)
-				of_property_read_string_index(np, "cm-chargers",
-						i, &desc->psy_charger_stat[i]);
-		} else {
+		if (!desc->psy_charger_stat)
 			return ERR_PTR(-ENOMEM);
-		}
+
+		for (i = 0; i < num_chgs; i++)
+			of_property_read_string_index(np, "cm-chargers",
+						      i, &desc->psy_charger_stat[i]);
 	}
 
 	of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge);