]> git.karo-electronics.de Git - linux-beck.git/commitdiff
gpio: fix warning about iterator
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Sun, 27 Dec 2015 13:36:50 +0000 (19:06 +0530)
committerLinus Walleij <linus.walleij@linaro.org>
Sun, 27 Dec 2015 22:51:21 +0000 (23:51 +0100)
We were getting build warning about "iterator" being used uninitialized.
Use iterator properly to fix the build warning and in the process remove
the variable "pos" which is not required now.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index 975a548bd71e6c5832c4d71c15b490ff7e36ca3a..ca6630207c66c5ee7736347aa2968170657f353a 100644 (file)
@@ -189,23 +189,21 @@ EXPORT_SYMBOL_GPL(gpiod_get_direction);
  */
 static int gpiochip_add_to_list(struct gpio_chip *chip)
 {
-       struct list_head *pos;
        struct gpio_chip *iterator;
        struct gpio_chip *previous = NULL;
 
        if (list_empty(&gpio_chips)) {
-               pos = gpio_chips.next;
-               goto found;
+               list_add_tail(&chip->list, &gpio_chips);
+               return 0;
        }
 
-       list_for_each(pos, &gpio_chips) {
-               iterator = list_entry(pos, struct gpio_chip, list);
+       list_for_each_entry(iterator, &gpio_chips, list) {
                if (iterator->base >= chip->base + chip->ngpio) {
                        /*
                         * Iterator is the first GPIO chip so there is no
                         * previous one
                         */
-                       if (previous == NULL) {
+                       if (!previous) {
                                goto found;
                        } else {
                                /*
@@ -221,7 +219,13 @@ static int gpiochip_add_to_list(struct gpio_chip *chip)
                previous = iterator;
        }
 
-       /* We are beyond the last chip in the list */
+       /*
+        * We are beyond the last chip in the list and iterator now
+        * points to the head.
+        * Let iterator point to the last chip in the list.
+        */
+
+       iterator = list_last_entry(&gpio_chips, struct gpio_chip, list);
        if (iterator->base + iterator->ngpio <= chip->base)
                goto found;
 
@@ -230,7 +234,7 @@ static int gpiochip_add_to_list(struct gpio_chip *chip)
        return -EBUSY;
 
 found:
-       list_add_tail(&chip->list, pos);
+       list_add_tail(&chip->list, &iterator->list);
        return 0;
 }