All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power_supply: collie_battery: simplify collie_bat_probe error handling
@ 2011-08-26  3:14 Axel Lin
  2011-08-26  7:09 ` Igor Grinberg
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2011-08-26  3:14 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Kunze, Anton Vorontsov

I think this change is better in readability.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/power/collie_battery.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/power/collie_battery.c b/drivers/power/collie_battery.c
index 548d263..89d6fcd 100644
--- a/drivers/power/collie_battery.c
+++ b/drivers/power/collie_battery.c
@@ -322,10 +322,8 @@ static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
 
 	for (i = 0; i < ARRAY_SIZE(gpios); i++) {
 		ret = gpio_request(gpios[i].gpio, gpios[i].name);
-		if (ret) {
-			i--;
+		if (ret)
 			goto err_gpio;
-		}
 
 		if (gpios[i].output)
 			ret = gpio_direction_output(gpios[i].gpio,
@@ -333,8 +331,10 @@ static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
 		else
 			ret = gpio_direction_input(gpios[i].gpio);
 
-		if (ret)
+		if (ret) {
+			gpio_free(gpios[i].gpio);
 			goto err_gpio;
+		}
 	}
 
 	mutex_init(&collie_bat_main.work_lock);
@@ -363,10 +363,8 @@ err_psy_reg_main:
 
 	/* see comment in collie_bat_remove */
 	cancel_work_sync(&bat_work);
-
-	i--;
 err_gpio:
-	for (; i >= 0; i--)
+	while (--i >= 0)
 		gpio_free(gpios[i].gpio);
 
 	return ret;
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power_supply: collie_battery: simplify collie_bat_probe error handling
  2011-08-26  3:14 [PATCH] power_supply: collie_battery: simplify collie_bat_probe error handling Axel Lin
@ 2011-08-26  7:09 ` Igor Grinberg
  0 siblings, 0 replies; 2+ messages in thread
From: Igor Grinberg @ 2011-08-26  7:09 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Thomas Kunze, Anton Vorontsov

Mailer problem, sorry, sending once again...


Hi Axel,



On 08/26/11 06:14, Axel Lin wrote:
> I think this change is better in readability.
>
> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---

May be just convert it to use struct gpio and gpio_<request|free>_array() calls?
Because right now it uses the same concept, but really awkward...

>  drivers/power/collie_battery.c |   12 +++++-------
>  1 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/power/collie_battery.c b/drivers/power/collie_battery.c
> index 548d263..89d6fcd 100644
> --- a/drivers/power/collie_battery.c
> +++ b/drivers/power/collie_battery.c
> @@ -322,10 +322,8 @@ static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
>  
>  	for (i = 0; i < ARRAY_SIZE(gpios); i++) {
>  		ret = gpio_request(gpios[i].gpio, gpios[i].name);
> -		if (ret) {
> -			i--;
> +		if (ret)
>  			goto err_gpio;
> -		}
>  
>  		if (gpios[i].output)
>  			ret = gpio_direction_output(gpios[i].gpio,
> @@ -333,8 +331,10 @@ static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
>  		else
>  			ret = gpio_direction_input(gpios[i].gpio);
>  
> -		if (ret)
> +		if (ret) {
> +			gpio_free(gpios[i].gpio);
>  			goto err_gpio;
> +		}
>  	}
>  
>  	mutex_init(&collie_bat_main.work_lock);
> @@ -363,10 +363,8 @@ err_psy_reg_main:
>  
>  	/* see comment in collie_bat_remove */
>  	cancel_work_sync(&bat_work);
> -
> -	i--;
>  err_gpio:
> -	for (; i >= 0; i--)
> +	while (--i >= 0)
>  		gpio_free(gpios[i].gpio);
>  
>  	return ret;

-- 
Regards,
Igor.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-26  7:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26  3:14 [PATCH] power_supply: collie_battery: simplify collie_bat_probe error handling Axel Lin
2011-08-26  7:09 ` Igor Grinberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.