]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
pinctrl: sunxi: fix 'pctrl->functions' allocation in sunxi_pinctrl_build_state
authorYueHaibing <yuehaibing@huawei.com>
Fri, 21 Sep 2018 01:59:41 +0000 (09:59 +0800)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:58:14 +0000 (19:58 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836802
[ Upstream commit a4925311a5443126ecc90671a1604ea7b0f5b32e ]

fixes following Smatch static check warning:

 ./drivers/pinctrl/sunxi/pinctrl-sunxi.c:1112 sunxi_pinctrl_build_state()
 warn: passing devm_ allocated variable to kfree. 'pctrl->functions'

As we will be calling krealloc() on pointer 'pctrl->functions', which means
kfree() will be called in there, devm_kzalloc() shouldn't be used with
the allocation in the first place.  Fix the warning by calling kcalloc()
and managing the free procedure in error path on our own.

Fixes: 0e37f88d9ad8 ("ARM: sunxi: Add pinctrl driver for Allwinner SoCs")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/pinctrl/sunxi/pinctrl-sunxi.c

index 4b6cb25bc796f86d00b9ab56b7144f20bfb2d610..3c85e5e04b43fb69f7c68007bc9d4f8ef0fa956c 100644 (file)
@@ -1077,9 +1077,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
         * We suppose that we won't have any more functions than pins,
         * we'll reallocate that later anyway
         */
-       pctl->functions = devm_kzalloc(&pdev->dev,
-                                      pctl->ngroups * sizeof(*pctl->functions),
-                                      GFP_KERNEL);
+       pctl->functions = kcalloc(pctl->ngroups,
+                                 sizeof(*pctl->functions),
+                                 GFP_KERNEL);
        if (!pctl->functions)
                return -ENOMEM;
 
@@ -1130,16 +1130,20 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
 
                        func_item = sunxi_pinctrl_find_function_by_name(pctl,
                                                                        func->name);
-                       if (!func_item)
+                       if (!func_item) {
+                               kfree(pctl->functions);
                                return -EINVAL;
+                       }
 
                        if (!func_item->groups) {
                                func_item->groups =
                                        devm_kzalloc(&pdev->dev,
                                                     func_item->ngroups * sizeof(*func_item->groups),
                                                     GFP_KERNEL);
-                               if (!func_item->groups)
+                               if (!func_item->groups) {
+                                       kfree(pctl->functions);
                                        return -ENOMEM;
+                               }
                        }
 
                        func_grp = func_item->groups;