gpio: of: add missing of_node_put() in of_gpiochip_scan_gpios()
authorWei Yongjun <weiyongjun1@huawei.com>
Sat, 29 Oct 2016 16:13:52 +0000 (16:13 +0000)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 31 Oct 2016 08:23:45 +0000 (09:23 +0100)
When terminating for_each_available_child_of_node() iteration
with break or return, of_node_put() should be used to prevent
stale device node references from being left behind.

This is detected by Coccinelle semantic patch.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib-of.c

index 3fa4e84b4327122e12355d6aa20dbf4408ae3834..5236966b1bdfc4008466cf25a583218a60fe4b12 100644 (file)
@@ -247,8 +247,10 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
                        continue;
 
                ret = gpiod_hog(desc, name, lflags, dflags);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(np);
                        return ret;
+               }
        }
 
        return 0;