summaryrefslogtreecommitdiff
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorAntonio Borneo <antonio.borneo@foss.st.com>2023-11-07 12:05:20 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-02-21 13:49:28 +0100
commite382b6946d03c62d58d2a6babedabc63d0ecc509 (patch)
treee0668fbeff512dfb854c8ac97d18380f11cefa2b /drivers/pinctrl
parent62d33b9e68bd7735a03bc3e3a88d151eab1378b5 (diff)
downloadlinux-e382b6946d03c62d58d2a6babedabc63d0ecc509.tar.gz
linux-e382b6946d03c62d58d2a6babedabc63d0ecc509.tar.bz2
linux-e382b6946d03c62d58d2a6babedabc63d0ecc509.zip
pinctrl: stm32: fix array read out of bound
commit edd48fd9d45370d6c8ba0dd834fcc51ff688cc87 upstream. 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/stm32/pinctrl-stm32.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index a4f628675dbb..4a3f5f5b966d 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1282,9 +1282,11 @@ static struct stm32_desc_pin *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_pi
int i;
/* With few exceptions (e.g. bank 'Z'), pin number matches with pin index in array */
- pin_desc = pctl->pins + stm32_pin_nb;
- if (pin_desc->pin.number == stm32_pin_nb)
- return pin_desc;
+ if (stm32_pin_nb < pctl->npins) {
+ pin_desc = pctl->pins + stm32_pin_nb;
+ if (pin_desc->pin.number == stm32_pin_nb)
+ return pin_desc;
+ }
/* Otherwise, loop all array to find the pin with the right number */
for (i = 0; i < pctl->npins; i++) {