linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: nuvoton: Add NULL pointer check in npcm8xx_gpio_fw()
@ 2025-02-12 20:23 Chenyuan Yang
  0 siblings, 0 replies; only message in thread
From: Chenyuan Yang @ 2025-02-12 20:23 UTC (permalink / raw)
  To: avifishman70, tmaimon77, tali.perry1, venture, yuenn,
	benjaminfair, linus.walleij
  Cc: openbmc, linux-gpio, linux-kernel, Chenyuan Yang

Add a NULL pointer check for pctrl->gpio_bank[id].gc.label in
npcm8xx_gpio_fw() to prevent potential NULL pointer dereference.
This is similar to the fix in commit 3027e7b15b02 
("ice: Fix some null pointer dereference issues in ice_ptp.c").

The npcm7xx driver already has this check in its npcm7xx_gpio_fw()
function, which provides similar functionality.
Add the same protection to npcm8xx.

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

diff --git a/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c b/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c
index 471f644c5eef..d09a5e9b2eca 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c
@@ -2374,6 +2374,9 @@ static int npcm8xx_gpio_fw(struct npcm8xx_pinctrl *pctrl)
 		pctrl->gpio_bank[id].gc.parent = dev;
 		pctrl->gpio_bank[id].gc.fwnode = child;
 		pctrl->gpio_bank[id].gc.label = devm_kasprintf(dev, GFP_KERNEL, "%pfw", child);
+		if (!pctrl->gpio_bank[id].gc.label)
+			return -ENOMEM;
+
 		pctrl->gpio_bank[id].gc.dbg_show = npcmgpio_dbg_show;
 		pctrl->gpio_bank[id].direction_input = pctrl->gpio_bank[id].gc.direction_input;
 		pctrl->gpio_bank[id].gc.direction_input = npcmgpio_direction_input;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-02-12 20:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 20:23 [PATCH] pinctrl: nuvoton: Add NULL pointer check in npcm8xx_gpio_fw() Chenyuan Yang

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