Skip to content

Commit

Permalink
pinctrl: lpc18xx: ensure ngroups is initialized at correct place
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Joachim Eastwood <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
Colin Ian King authored and linusw committed Mar 7, 2016
1 parent 35cec70 commit 5e9a207
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/pinctrl/pinctrl-lpc18xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5e9a207

Please sign in to comment.