pinctrl: stm32: fix array read out of bound
authorAntonio Borneo <antonio.borneo@foss.st.com>
Tue, 7 Nov 2023 11:05:20 +0000 (12:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Dec 2023 07:52:21 +0000 (08:52 +0100)
commita9659016f9ebc0868b74d1982e38d3af4511f948
treecd9c54ae76f024ed6cb9a3010ebcabfa4c3491db
parent3e3fa8056fd259f34e6f0c02b54d17893114c909
pinctrl: stm32: fix array read out of bound

[ Upstream commit edd48fd9d45370d6c8ba0dd834fcc51ff688cc87 ]

The existing code does not verify if the "tentative" index exceeds
the size of the array, causing out of bound read.
Issue identified with kasan.

Check the index before using it.

Signed-off-by: Antonio Borneo <antonio.borneo@foss.st.com>
Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
Link: https://lore.kernel.org/r/20231107110520.4449-1-antonio.borneo@foss.st.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/stm32/pinctrl-stm32.c