diff mbox

[v7,05/15] gpio: fix wrong checking condition for gpio range

Message ID 1358494279-16503-6-git-send-email-haojian.zhuang@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Haojian Zhuang Jan. 18, 2013, 7:31 a.m. UTC
Since index++ calculates from 0, the checking condition of "while
(index++)" is always fake. So replace it by unconditional loop.

Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
---
 drivers/gpio/gpiolib-of.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Sergei Shtylyov Jan. 18, 2013, 12:18 p.m. UTC | #1
Hello.

On 18-01-2013 11:31, Haojian Zhuang wrote:

> Since index++ calculates from 0, the checking condition of "while
> (index++)" is always fake. So replace it by unconditional loop.

> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
> ---
>   drivers/gpio/gpiolib-of.c |    6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index b1f0682..011e1e98 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -228,7 +228,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
>   	if (!np)
>   		return;
>
> -	do {
> +	for (;;) {

    Why not:

	for (;; index++) {

>   		ret = of_parse_phandle_with_args(np, "gpio-ranges",
>   				"#gpio-range-cells", index, &pinspec);
>   		if (ret)
> @@ -254,8 +254,8 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
>
>   		if (ret)
>   			break;
> -
> -	} while (index++);
> +		index++;
> +	}
>   }

WBR, Sergei
Sergei Shtylyov Jan. 18, 2013, 12:21 p.m. UTC | #2
On 18-01-2013 11:31, Haojian Zhuang wrote:

> Since index++ calculates from 0, the checking condition of "while
> (index++)" is always fake.

    You meanbt "false"?  Actually if 'index' starts from 0, the loop will end 
after the first iteration.

> So replace it by unconditional loop.

> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
> ---
>   drivers/gpio/gpiolib-of.c |    6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index b1f0682..011e1e98 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -228,7 +228,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
>   	if (!np)
>   		return;
>
> -	do {
> +	for (;;) {
>   		ret = of_parse_phandle_with_args(np, "gpio-ranges",
>   				"#gpio-range-cells", index, &pinspec);
>   		if (ret)
> @@ -254,8 +254,8 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
>
>   		if (ret)
>   			break;
> -
> -	} while (index++);
> +		index++;
> +	}
>   }

WBR, Sergei
Haojian Zhuang Jan. 18, 2013, 3:02 p.m. UTC | #3
On 18 January 2013 20:18, Sergei Shtylyov <sshtylyov@mvista.com> wrote:
> Hello.
>
>
> On 18-01-2013 11:31, Haojian Zhuang wrote:
>
>> Since index++ calculates from 0, the checking condition of "while
>> (index++)" is always fake. So replace it by unconditional loop.
>
>
>> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
>> ---
>>   drivers/gpio/gpiolib-of.c |    6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>
>
>> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
>> index b1f0682..011e1e98 100644
>> --- a/drivers/gpio/gpiolib-of.c
>> +++ b/drivers/gpio/gpiolib-of.c
>> @@ -228,7 +228,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip
>> *chip)
>>         if (!np)
>>                 return;
>>
>> -       do {
>> +       for (;;) {
>
>
>    Why not:
>
>         for (;; index++) {
>
OK. I'll update it.

>
>>                 ret = of_parse_phandle_with_args(np, "gpio-ranges",
>>                                 "#gpio-range-cells", index, &pinspec);
>>                 if (ret)
>> @@ -254,8 +254,8 @@ static void of_gpiochip_add_pin_range(struct gpio_chip
>> *chip)
>>
>>                 if (ret)
>>                         break;
>> -
>> -       } while (index++);
>> +               index++;
>> +       }
>>   }
>
>
> WBR, Sergei
>
diff mbox

Patch

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index b1f0682..011e1e98 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -228,7 +228,7 @@  static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
 	if (!np)
 		return;
 
-	do {
+	for (;;) {
 		ret = of_parse_phandle_with_args(np, "gpio-ranges",
 				"#gpio-range-cells", index, &pinspec);
 		if (ret)
@@ -254,8 +254,8 @@  static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
 
 		if (ret)
 			break;
-
-	} while (index++);
+		index++;
+	}
 }
 
 #else