diff mbox

Input: gpio_keys - fix NULL pointer dereference for dt case

Message ID 86D15885F63D1143A519F161FB828EAF11AF30@039-SN2MPN1-013.039d.mgd.msft.net (mailing list archive)
State New, archived
Headers show

Commit Message

Estevam Fabio-R49496 Aug. 17, 2012, 12:01 a.m. UTC
Dmitry,

Any comments about this patch?
diff mbox

Patch

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 6ee68ec..620ef24 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -559,7 +559,6 @@  gpio_keys_get_devtree_pdata(struct device *dev)
        struct gpio_keys_button *button;
        int error;
        int nbuttons;
-       int i;

        node = dev->of_node;
        if (!node) {
@@ -580,9 +579,11 @@  gpio_keys_get_devtree_pdata(struct device *dev)
                goto err_out;
        }

+       pdata->buttons = (struct gpio_keys_button *) (pdata + 1);
+       pdata->nbuttons = nbuttons;
+
        pdata->rep = !!of_get_property(node, "autorepeat", NULL);

-       i = 0;
        for_each_child_of_node(node, pp) {
                enum of_gpio_flags flags;

@@ -592,8 +593,13 @@  gpio_keys_get_devtree_pdata(struct device *dev)
                        continue;
                }

-               button = &pdata->buttons[i++];
-
+               button = pdata->buttons;
+
+               if (!button)    {
+                       error = -ENOMEM;
+                       goto err_free_pdata;
+               }
+
                button->gpio = of_get_gpio_flags(pp, 0, &flags);
                button->active_low = flags & OF_GPIO_ACTIVE_LOW;

@@ -614,6 +620,8 @@  gpio_keys_get_devtree_pdata(struct device *dev)
                if (of_property_read_u32(pp, "debounce-interval",
                                         &button->debounce_interval))
                        button->debounce_interval = 5;
+
+               button++;
        }

        if (pdata->nbuttons == 0) {