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


Groups > linux.kernel > #1298394

[PATCH v2] gpiolib: fix warning about iterator

From Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v2] gpiolib: fix warning about iterator
Date 2015-12-27 14:40 +0100
Message-ID <qKjIe-7Ca-23@gated-at.bofh.it> (permalink)
References <qK4Jc-6fM-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---

v1: at the end of the loop iterator will point to head and we are trying
to check its field.

 drivers/gpio/gpiolib.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index d72ac1f..6972b4e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] gpiolib: fix warning about iterator Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-12-26 09:00 +0100
  Re: [PATCH] gpiolib: fix warning about iterator Linus Walleij <linus.walleij@linaro.org> - 2015-12-26 22:40 +0100
    Re: [PATCH] gpiolib: fix warning about iterator Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-12-27 14:40 +0100
    [PATCH v2] gpiolib: fix warning about iterator Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-12-27 14:40 +0100
      Re: [PATCH v2] gpiolib: fix warning about iterator Linus Walleij <linus.walleij@linaro.org> - 2015-12-28 03:50 +0100

csiph-web