All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix warning about iterator
@ 2015-12-26  7:58 Sudip Mukherjee
  2015-12-26 21:31 ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-12-26  7:58 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot
  Cc: linux-kernel, linux-gpio, Sudip Mukherjee

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>
---
 drivers/gpio/gpiolib.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index d72ac1f..3619ce4 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 {
 				/*
@@ -230,7 +228,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


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

* Re: [PATCH] gpiolib: fix warning about iterator
  2015-12-26  7:58 [PATCH] gpiolib: fix warning about iterator Sudip Mukherjee
@ 2015-12-26 21:31 ` Linus Walleij
  2015-12-27 13:31   ` Sudip Mukherjee
  2015-12-27 13:36   ` [PATCH v2] " Sudip Mukherjee
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Walleij @ 2015-12-26 21:31 UTC (permalink / raw)
  To: Sudip Mukherjee, Ross Zwisler; +Cc: Alexandre Courbot, linux-kernel, linux-gpio

On Sat, Dec 26, 2015 at 8:58 AM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:

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

Aha there is a real patch solving the problem. Sorry Ross,
had to drop your patch and replace it with this.

Patch applied!

Yours,
Linus Walleij

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

* Re: [PATCH] gpiolib: fix warning about iterator
  2015-12-26 21:31 ` Linus Walleij
@ 2015-12-27 13:31   ` Sudip Mukherjee
  2015-12-27 13:36   ` [PATCH v2] " Sudip Mukherjee
  1 sibling, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2015-12-27 13:31 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Ross Zwisler, Alexandre Courbot, linux-kernel, linux-gpio

On Sat, Dec 26, 2015 at 10:31:15PM +0100, Linus Walleij wrote:
> On Sat, Dec 26, 2015 at 8:58 AM, Sudip Mukherjee
> <sudipm.mukherjee@gmail.com> wrote:
> 
> > 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>
> 
> Aha there is a real patch solving the problem. Sorry Ross,
> had to drop your patch and replace it with this.
> 
> Patch applied!

oops .. i think i have a small mistake in the patch. After the loop for
list_for_each_entry ends we are having:
        if (iterator->base + iterator->ngpio <= chip->base)
	                goto found;

But at the end of the loop iterator will point to head. The condition in
the loop is &pos->member != (head).
I am sending v2 as reply to this thread. It will be great if you can
review and apply that instead of this one.
Sorry for the inconvenience. I guess christmas effect. :)

regards
sudip

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

* [PATCH v2] gpiolib: fix warning about iterator
  2015-12-26 21:31 ` Linus Walleij
  2015-12-27 13:31   ` Sudip Mukherjee
@ 2015-12-27 13:36   ` Sudip Mukherjee
  2015-12-28  0:35     ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-12-27 13:36 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot
  Cc: linux-kernel, linux-gpio, Sudip Mukherjee

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


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

* Re: [PATCH v2] gpiolib: fix warning about iterator
  2015-12-27 13:36   ` [PATCH v2] " Sudip Mukherjee
@ 2015-12-28  0:35     ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2015-12-28  0:35 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: Alexandre Courbot, linux-kernel, linux-gpio

On Sun, Dec 27, 2015 at 2:36 PM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:

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

OK took the v1 out and applied this version instead.

Yours,
Linus Walleij

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

end of thread, other threads:[~2015-12-28  0:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-26  7:58 [PATCH] gpiolib: fix warning about iterator Sudip Mukherjee
2015-12-26 21:31 ` Linus Walleij
2015-12-27 13:31   ` Sudip Mukherjee
2015-12-27 13:36   ` [PATCH v2] " Sudip Mukherjee
2015-12-28  0:35     ` Linus Walleij

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.