pinctrl: lpc18xx: ensure ngroups is initialized at correct place
authorColin Ian King <colin.king@canonical.com>
Wed, 24 Feb 2016 17:32:50 +0000 (17:32 +0000)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 7 Mar 2016 03:28:05 +0000 (10:28 +0700)
The initialization of ngroups is occurring at the end of the
first iteration of the outer loop, which means that the
assignment  pins[ngroups++] = i is potentially indexing into
a region outside of array pins because ngroups is not initialized.
Instead, initialize ngroups in the inner loop before the first
inner loop iteration.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Joachim Eastwood <manabian@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-lpc18xx.c

index f0bebbe0682b9b18b622f47bc7cf5471e503ec92..ed1cfa7e43dd946e51c3fde4a527bff1eb52d794 100644 (file)
@@ -1170,9 +1170,8 @@ static int lpc18xx_create_group_func_map(struct device *dev,
        u16 pins[ARRAY_SIZE(lpc18xx_pins)];
        int func, ngroups, i;
 
-       for (func = 0; func < FUNC_MAX; ngroups = 0, func++) {
-
-               for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
+       for (func = 0; func < FUNC_MAX; func++) {
+               for (ngroups = 0, i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
                        if (lpc18xx_valid_pin_function(i, func))
                                pins[ngroups++] = i;
                }