diff mbox

gpiolib: fix warning about iterator

Message ID 1451116719-19158-1-git-send-email-sudipm.mukherjee@gmail.com
State New
Headers show

Commit Message

Sudip Mukherjee Dec. 26, 2015, 7:58 a.m. UTC
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(-)

Comments

Linus Walleij Dec. 26, 2015, 9:31 p.m. UTC | #1
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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sudip Mukherjee Dec. 27, 2015, 1:31 p.m. UTC | #2
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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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