linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: stm32: Add check for devm_kcalloc
@ 2023-10-31  8:08 Chen Ni
  2023-10-31 10:09 ` Valentin CARON
  2023-11-13 14:12 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Chen Ni @ 2023-10-31  8:08 UTC (permalink / raw)
  To: linus.walleij, mcoquelin.stm32, alexandre.torgue, robh,
	geert+renesas, jernej.skrabec, valentin.caron, bero, nichen,
	dario.binacchi, linux-gpio, linux-stm32, linux-arm-kernel,
	linux-kernel

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 <nichen@iscas.ac.cn>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: stm32: Add check for devm_kcalloc
  2023-10-31  8:08 [PATCH] pinctrl: stm32: Add check for devm_kcalloc Chen Ni
@ 2023-10-31 10:09 ` Valentin CARON
  2023-11-13 14:12 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Valentin CARON @ 2023-10-31 10:09 UTC (permalink / raw)
  To: Chen Ni, linus.walleij
  Cc: mcoquelin.stm32, alexandre.torgue, robh, geert+renesas, bero,
	jernej.skrabec, dario.binacchi, linux-arm-kernel, linux-stm32,
	linux-gpio, linux-kernel

Hi Chen,

Thank you for your patch:

Acked-by: Valentin Caron <valentin.caron@foss.st.com>

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 <nichen@iscas.ac.cn>
> ---
>   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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: stm32: Add check for devm_kcalloc
  2023-10-31  8:08 [PATCH] pinctrl: stm32: Add check for devm_kcalloc Chen Ni
  2023-10-31 10:09 ` Valentin CARON
@ 2023-11-13 14:12 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2023-11-13 14:12 UTC (permalink / raw)
  To: Chen Ni
  Cc: mcoquelin.stm32, alexandre.torgue, robh, geert+renesas,
	jernej.skrabec, valentin.caron, bero, dario.binacchi, linux-gpio,
	linux-stm32, linux-arm-kernel, linux-kernel

On Tue, Oct 31, 2023 at 9:09 AM Chen Ni <nichen@iscas.ac.cn> 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 <nichen@iscas.ac.cn>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-13 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31  8:08 [PATCH] pinctrl: stm32: Add check for devm_kcalloc Chen Ni
2023-10-31 10:09 ` Valentin CARON
2023-11-13 14:12 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).