Skip to content

Commit 289b950

Browse files
Dan Carpenterlinusw
authored andcommitted
gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
Using BUG_ON() is discouraged and also the check wasn't done early enough to prevent an out of bounds access. Check earlier and return an error instead of calling BUG(). Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent c056ccf commit 289b950

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/gpio/gpio-nomadik.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
533533
}
534534

535535
#ifdef CONFIG_PINCTRL_NOMADIK
536+
if (id >= ARRAY_SIZE(nmk_gpio_chips)) {
537+
dev_err(dev, "populate: invalid id: %u\n", id);
538+
platform_device_put(gpio_pdev);
539+
return ERR_PTR(-EINVAL);
540+
}
536541
/* Already populated? */
537542
nmk_chip = nmk_gpio_chips[id];
538543
if (nmk_chip) {
@@ -606,7 +611,6 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
606611
}
607612

608613
#ifdef CONFIG_PINCTRL_NOMADIK
609-
BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
610614
nmk_gpio_chips[id] = nmk_chip;
611615
#endif
612616
return nmk_chip;

0 commit comments

Comments
 (0)