@@ -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) {