linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: Fix potential NULL pointer dereference
@ 2025-02-10 23:25 Chenyuan Yang
  2025-02-11  7:38 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chenyuan Yang @ 2025-02-10 23:25 UTC (permalink / raw)
  To: geert+renesas, linus.walleij, richardcochran, matthias.bgg,
	angelogioacchino.delregno
  Cc: linux-renesas-soc, linux-gpio, netdev, linux-kernel, zzjas98,
	Chenyuan Yang

The `chip.label` could be NULL. Add missing check in the
rza2_gpio_register().
This is similar to commit 3027e7b15b02 
("ice: Fix some null pointer dereference issues in ice_ptp.c").
Besides, mediatek_gpio_bank_probe() in drivers/gpio/gpio-mt7621.c also
has a very similar check.

Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
---
 drivers/pinctrl/renesas/pinctrl-rza2.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pinctrl/renesas/pinctrl-rza2.c b/drivers/pinctrl/renesas/pinctrl-rza2.c
index dd1f8c29d3e7..3da8b0d389c9 100644
--- a/drivers/pinctrl/renesas/pinctrl-rza2.c
+++ b/drivers/pinctrl/renesas/pinctrl-rza2.c
@@ -246,6 +246,9 @@ static int rza2_gpio_register(struct rza2_pinctrl_priv *priv)
 	int ret;
 
 	chip.label = devm_kasprintf(priv->dev, GFP_KERNEL, "%pOFn", np);
+	if (!chip.label)
+		return -ENOMEM;
+
 	chip.parent = priv->dev;
 	chip.ngpio = priv->npins;
 
-- 
2.34.1


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

* Re: [PATCH] pinctrl: Fix potential NULL pointer dereference
  2025-02-10 23:25 [PATCH] pinctrl: Fix potential NULL pointer dereference Chenyuan Yang
@ 2025-02-11  7:38 ` Geert Uytterhoeven
  2025-02-12  8:35 ` Matthias Brugger
  2025-02-12 12:45 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2025-02-11  7:38 UTC (permalink / raw)
  To: Chenyuan Yang
  Cc: linus.walleij, richardcochran, matthias.bgg,
	angelogioacchino.delregno, linux-renesas-soc, linux-gpio, netdev,
	linux-kernel, zzjas98

On Tue, 11 Feb 2025 at 00:25, Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> The `chip.label` could be NULL. Add missing check in the
> rza2_gpio_register().
> This is similar to commit 3027e7b15b02
> ("ice: Fix some null pointer dereference issues in ice_ptp.c").
> Besides, mediatek_gpio_bank_probe() in drivers/gpio/gpio-mt7621.c also
> has a very similar check.
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-pinctrl for v6.15.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] pinctrl: Fix potential NULL pointer dereference
  2025-02-10 23:25 [PATCH] pinctrl: Fix potential NULL pointer dereference Chenyuan Yang
  2025-02-11  7:38 ` Geert Uytterhoeven
@ 2025-02-12  8:35 ` Matthias Brugger
  2025-02-12 12:45 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Matthias Brugger @ 2025-02-12  8:35 UTC (permalink / raw)
  To: Chenyuan Yang, geert+renesas, linus.walleij, richardcochran,
	angelogioacchino.delregno
  Cc: linux-renesas-soc, linux-gpio, netdev, linux-kernel, zzjas98



On 11/02/2025 00:25, Chenyuan Yang wrote:
> The `chip.label` could be NULL. Add missing check in the
> rza2_gpio_register().
> This is similar to commit 3027e7b15b02
> ("ice: Fix some null pointer dereference issues in ice_ptp.c").
> Besides, mediatek_gpio_bank_probe() in drivers/gpio/gpio-mt7621.c also
> has a very similar check.
> 
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/pinctrl/renesas/pinctrl-rza2.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pinctrl/renesas/pinctrl-rza2.c b/drivers/pinctrl/renesas/pinctrl-rza2.c
> index dd1f8c29d3e7..3da8b0d389c9 100644
> --- a/drivers/pinctrl/renesas/pinctrl-rza2.c
> +++ b/drivers/pinctrl/renesas/pinctrl-rza2.c
> @@ -246,6 +246,9 @@ static int rza2_gpio_register(struct rza2_pinctrl_priv *priv)
>   	int ret;
>   
>   	chip.label = devm_kasprintf(priv->dev, GFP_KERNEL, "%pOFn", np);
> +	if (!chip.label)
> +		return -ENOMEM;
> +
>   	chip.parent = priv->dev;
>   	chip.ngpio = priv->npins;
>   


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

* Re: [PATCH] pinctrl: Fix potential NULL pointer dereference
  2025-02-10 23:25 [PATCH] pinctrl: Fix potential NULL pointer dereference Chenyuan Yang
  2025-02-11  7:38 ` Geert Uytterhoeven
  2025-02-12  8:35 ` Matthias Brugger
@ 2025-02-12 12:45 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-02-12 12:45 UTC (permalink / raw)
  To: Chenyuan Yang, linux-gpio, linux-renesas-soc, netdev,
	Angelo Gioacchino Del Regno, Geert Uytterhoeven, Linus Walleij,
	Matthias Brugger, Richard Cochran
  Cc: LKML, Zijie Zhao

> The `chip.label` could be NULL. Add missing check in the
> rza2_gpio_register().

Another wording suggestion:
The data structure member “chip.label” could become NULL
after a failed devm_kasprintf() call in the implementation
of the function “rza2_gpio_register”.
Thus add a check for such a return value.


How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14-rc2#n145


Can a summary phrase like “Prevent null pointer dereference in rza2_gpio_register()”
be nicer?


> This is similar to commit 3027e7b15b02
> ("ice: Fix some null pointer dereference issues in ice_ptp.c").
> Besides, mediatek_gpio_bank_probe() in drivers/gpio/gpio-mt7621.c also
> has a very similar check.

I find such auxiliary information not so relevant here.

Regards,
Markus

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

end of thread, other threads:[~2025-02-12 12:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 23:25 [PATCH] pinctrl: Fix potential NULL pointer dereference Chenyuan Yang
2025-02-11  7:38 ` Geert Uytterhoeven
2025-02-12  8:35 ` Matthias Brugger
2025-02-12 12:45 ` Markus Elfring

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).