Skip to contentSkip to conversation

pinctrl: Fix potential NULL pointer dereference

PATCH In review Chenyuan Yang 4 participants 4 messages Feb 10, 2025 – Feb 12, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: Fix potential NULL pointer dereference

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.

---
 drivers/pinctrl/renesas/pinctrl-rza2.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pinctrl/renesas/pinctrl-rza2.c +3 -0
index dd1f8c29d3e7..3da8b0d389c9 100644
@@ -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;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · 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.

i.e. will queue in renesas-pinctrl for v6.15.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
Reviewed-by on v1 1/1
#2 lore raw
In reply to Chenyuan Yang
Quoted 8 lines · 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.

Quoted 18 lines
---
  drivers/pinctrl/renesas/pinctrl-rza2.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/pinctrl/renesas/pinctrl-rza2.c +3 -0
index dd1f8c29d3e7..3da8b0d389c9 100644
@@ -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;
 
#3 lore raw
In reply to Chenyuan Yang
Quoted 2 lines

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?

Quoted 4 lines

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