Commit 289b950b authored by Dan Carpenter's avatar Dan Carpenter Committed by Linus Walleij

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: default avatarDan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/ae643df0-3a3e-4270-8dbf-be390ee4b478@moroto.mountainSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent c056ccff
...@@ -533,6 +533,11 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode, ...@@ -533,6 +533,11 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
} }
#ifdef CONFIG_PINCTRL_NOMADIK #ifdef CONFIG_PINCTRL_NOMADIK
if (id >= ARRAY_SIZE(nmk_gpio_chips)) {
dev_err(dev, "populate: invalid id: %u\n", id);
platform_device_put(gpio_pdev);
return ERR_PTR(-EINVAL);
}
/* Already populated? */ /* Already populated? */
nmk_chip = nmk_gpio_chips[id]; nmk_chip = nmk_gpio_chips[id];
if (nmk_chip) { if (nmk_chip) {
...@@ -606,7 +611,6 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode, ...@@ -606,7 +611,6 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
} }
#ifdef CONFIG_PINCTRL_NOMADIK #ifdef CONFIG_PINCTRL_NOMADIK
BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
nmk_gpio_chips[id] = nmk_chip; nmk_gpio_chips[id] = nmk_chip;
#endif #endif
return nmk_chip; return nmk_chip;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment