gpio: make the iterator point to last handle
authorLinus Walleij <linus.walleij@linaro.org>
Sat, 18 Jun 2016 08:56:43 +0000 (10:56 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Sat, 18 Jun 2016 08:56:43 +0000 (10:56 +0200)
When initializing the GPIO handles, we use the iterator (i)
to back off if something goes wrong. But since the iterator
is also used after we pass the loop, we must decrement by
one after exiting the loop so that we point at the last
element in the array.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Walter Harms <wharms@bfs.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index c826844..b504364 100644 (file)
@@ -474,6 +474,8 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
                dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
                        offset);
        }
+       /* Let i point at the last handle */
+       i--;
        lh->numdescs = handlereq.lines;
 
        fd = anon_inode_getfd("gpio-linehandle",