pinctrl: axp209: Fix NULL pointer dereference after allocation
authorAditya Pakki <pakki001@umn.edu>
Tue, 12 Mar 2019 15:19:10 +0000 (10:19 -0500)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 8 Apr 2019 09:20:28 +0000 (11:20 +0200)
axp20x_build_funcs_groups allocates groups via devm_kcalloc and tries to
dereference without checking for NULL. This patch avoids such a
scenario.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-axp209.c

index afd0b533c40aa733ca20b0b9011b768bcd365b47..4fcf7262bed921ce28127e55640b18568fdc63aa 100644 (file)
@@ -366,6 +366,8 @@ static int axp20x_build_funcs_groups(struct platform_device *pdev)
                pctl->funcs[i].groups = devm_kcalloc(&pdev->dev,
                                                     npins, sizeof(char *),
                                                     GFP_KERNEL);
+               if (!pctl->funcs[i].groups)
+                       return -ENOMEM;
                for (pin = 0; pin < npins; pin++)
                        pctl->funcs[i].groups[pin] = pctl->desc->pins[pin].name;
        }