Input: gpio_keys - fix leaking DT node references
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 20 Oct 2016 22:11:45 +0000 (15:11 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 8 Nov 2016 00:24:30 +0000 (16:24 -0800)
for_each_available_child_of_node(node, pp) takes reference to 'pp' and
drops it when attempting next iteration. However if we exit the loop early
we need to drop the reference ourselves.

Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/gpio_keys.c

index 8f7c20b9cc5c00341fe7763be561eb685f5bd31f..d75a25c187aef7862c9ac77c0f483154cf1cbf63 100644 (file)
@@ -659,6 +659,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
                                        dev_err(dev,
                                                "Failed to get gpio flags, error: %d\n",
                                                error);
+                               of_node_put(pp);
                                return ERR_PTR(error);
                        }
                } else {
@@ -669,12 +670,14 @@ gpio_keys_get_devtree_pdata(struct device *dev)
 
                if (!gpio_is_valid(button->gpio) && !button->irq) {
                        dev_err(dev, "Found button without gpios or irqs\n");
+                       of_node_put(pp);
                        return ERR_PTR(-EINVAL);
                }
 
                if (of_property_read_u32(pp, "linux,code", &button->code)) {
                        dev_err(dev, "Button without keycode: 0x%x\n",
                                button->gpio);
+                       of_node_put(pp);
                        return ERR_PTR(-EINVAL);
                }