pinctrl: stm32: add missing of_node_put
authorJunlin Yang <yangjunlin@yulong.com>
Mon, 15 Feb 2021 10:36:43 +0000 (18:36 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Wed, 10 Mar 2021 13:41:12 +0000 (14:41 +0100)
Fix OF node leaks by calling of_node_put in
for_each_available_child_of_node when the cycle returns.

Generated by: scripts/coccinelle/iterators/for_each_child.cocci

Signed-off-by: Junlin Yang <yangjunlin@yulong.com>
Link: https://lore.kernel.org/r/20210215103643.898-1-angkery@163.com
Acked-by: Fabien Dessenne <fabien.dessenne@foss.st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/stm32/pinctrl-stm32.c

index 7d9bdedcd71bbee364570f3191b0ff1fa9b9aeb8..da72e3e5c08d65dcf32048e861181c2e6da2684c 100644 (file)
@@ -1542,8 +1542,10 @@ int stm32_pctl_probe(struct platform_device *pdev)
                if (of_property_read_bool(child, "gpio-controller")) {
                        bank->rstc = of_reset_control_get_exclusive(child,
                                                                    NULL);
-                       if (PTR_ERR(bank->rstc) == -EPROBE_DEFER)
+                       if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) {
+                               of_node_put(child);
                                return -EPROBE_DEFER;
+                       }
 
                        bank->clk = of_clk_get_by_name(child, NULL);
                        if (IS_ERR(bank->clk)) {
@@ -1551,6 +1553,7 @@ int stm32_pctl_probe(struct platform_device *pdev)
                                        dev_err(dev,
                                                "failed to get clk (%ld)\n",
                                                PTR_ERR(bank->clk));
+                               of_node_put(child);
                                return PTR_ERR(bank->clk);
                        }
                        i++;