pinctrl: imx: Check for memory allocation failure
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 6 May 2017 08:23:59 +0000 (10:23 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 22 May 2017 08:39:25 +0000 (10:39 +0200)
If 'devm_kzalloc' fails, a NULL pointer will be dereferenced.
Return -ENOMEM instead, as done for the other memory allocation just a
few lines below.
BTW, change the 'devm_kzalloc' into a 'devm_kcalloc'.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/freescale/pinctrl-imx.c

index 74bd90dfd7b1650acde5dc19f369b2cfc897362b..90a946c028fffd9117064c0dc22ddc9328787d88 100644 (file)
@@ -581,9 +581,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
                dev_err(info->dev, "no groups defined in %s\n", np->full_name);
                return -EINVAL;
        }
-       func->group_names = devm_kzalloc(info->dev,
-                                        func->num_group_names *
+       func->group_names = devm_kcalloc(info->dev, func->num_group_names,
                                         sizeof(char *), GFP_KERNEL);
+       if (!func->group_names)
+               return -ENOMEM;
 
        for_each_child_of_node(np, child) {
                func->group_names[i] = child->name;