]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: nuvoton: npcm8xx: Add NULL check in npcm8xx_gpio_fw
authorCharles Han <hanchunchao@inspur.com>
Wed, 12 Feb 2025 10:05:32 +0000 (18:05 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 25 Feb 2025 16:21:50 +0000 (17:21 +0100)
devm_kasprintf() calls can return null pointers on failure.
But the return values were not checked in npcm8xx_gpio_fw().
Add NULL check in npcm8xx_gpio_fw(), to handle kernel NULL
pointer dereference error.

Fixes: acf4884a5717 ("pinctrl: nuvoton: add NPCM8XX pinctrl and GPIO driver")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
Link: https://lore.kernel.org/20250212100532.4317-1-hanchunchao@inspur.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/nuvoton/pinctrl-npcm8xx.c

index 471f644c5eef2c87aeec50d3eca07bbe3663edd5..d09a5e9b2eca538caed8aab132f14c55892c1621 100644 (file)
@@ -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 == NULL)
+                       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;