]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: stm32: check devm_kasprintf() returned value
authorMa Ke <make24@iscas.ac.cn>
Fri, 6 Sep 2024 10:03:26 +0000 (18:03 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 1 Oct 2024 12:03:34 +0000 (14:03 +0200)
devm_kasprintf() can return a NULL pointer on failure but this returned
value is not checked. Fix this lack and check the returned value.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Link: https://lore.kernel.org/20240906100326.624445-1-make24@iscas.ac.cn
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/stm32/pinctrl-stm32.c

index a8673739871d811c736312a2b6d841cede7738f7..5b7fa77c118436f2a94ef92b92ef8d5ede0c81ff 100644 (file)
@@ -1374,10 +1374,15 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
 
        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)
+               if (stm32_pin && stm32_pin->pin.name) {
                        names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
-               else
+                       if (!names[i]) {
+                               err = -ENOMEM;
+                               goto err_clk;
+                       }
+               } else {
                        names[i] = NULL;
+               }
        }
 
        bank->gpio_chip.names = (const char * const *)names;