Skip to content

Commit 762ef7d

Browse files
andy-shevlinusw
authored andcommitted
pinctrl: at91: Fix possible out-of-boundary access
at91_gpio_probe() doesn't check that given OF alias is not available or something went wrong when trying to get it. This might have consequences when accessing gpio_chips array with that value as an index. Note, that BUG() can be compiled out and hence won't actually perform the required checks. Fixes: 6732ae5 ("ARM: at91: add pinctrl support") Signed-off-by: Andy Shevchenko <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 3b38cce commit 762ef7d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/pinctrl/pinctrl-at91.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,12 +1822,16 @@ static int at91_gpio_probe(struct platform_device *pdev)
18221822
struct at91_gpio_chip *at91_chip = NULL;
18231823
struct gpio_chip *chip;
18241824
struct pinctrl_gpio_range *range;
1825+
int alias_idx;
18251826
int ret = 0;
18261827
int irq, i;
1827-
int alias_idx = of_alias_get_id(np, "gpio");
18281828
uint32_t ngpio;
18291829
char **names;
18301830

1831+
alias_idx = of_alias_get_id(np, "gpio");
1832+
if (alias_idx < 0)
1833+
return alias_idx;
1834+
18311835
BUG_ON(alias_idx >= ARRAY_SIZE(gpio_chips));
18321836
if (gpio_chips[alias_idx])
18331837
return dev_err_probe(dev, -EBUSY, "%d slot is occupied.\n", alias_idx);

0 commit comments

Comments
 (0)