Add check for the return value of devm_kcalloc() and return the error
if it fails in order to avoid NULL pointer dereference.
Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
Signed-off-by: Chen Ni <[email protected]>
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index a73385a431de..419eca49ccec 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1378,6 +1378,11 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
}
names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
+ if (!names) {
+ err = -ENOMEM;
+ goto err_clk;
+ }
+
for (i = 0; i < npins; i++) {
stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
if (stm32_pin && stm32_pin->pin.name)
--
2.25.1
Hi Chen,
Thank you for your patch:
Acked-by: Valentin Caron <[email protected]>
Regards,
Valentin
On 10/31/23 09:08, Chen Ni wrote:
> Add check for the return value of devm_kcalloc() and return the error
> if it fails in order to avoid NULL pointer dereference.
>
> Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
> Signed-off-by: Chen Ni <[email protected]>
> ---
> drivers/pinctrl/stm32/pinctrl-stm32.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index a73385a431de..419eca49ccec 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -1378,6 +1378,11 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
> }
>
> names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
> + if (!names) {
> + err = -ENOMEM;
> + goto err_clk;
> + }
> +
> for (i = 0; i < npins; i++) {
> stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
> if (stm32_pin && stm32_pin->pin.name)