Input: gpio_keys - convert to use devm_*
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
1f9e1470ab
commit
5d422f2e78
1 changed files with 25 additions and 49 deletions
|
@ -578,23 +578,18 @@ gpio_keys_get_devtree_pdata(struct device *dev)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
node = dev->of_node;
|
node = dev->of_node;
|
||||||
if (!node) {
|
if (!node)
|
||||||
error = -ENODEV;
|
return ERR_PTR(-ENODEV);
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbuttons = of_get_child_count(node);
|
nbuttons = of_get_child_count(node);
|
||||||
if (nbuttons == 0) {
|
if (nbuttons == 0)
|
||||||
error = -ENODEV;
|
return ERR_PTR(-ENODEV);
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button),
|
pdata = devm_kzalloc(dev,
|
||||||
GFP_KERNEL);
|
sizeof(*pdata) + nbuttons * sizeof(*button),
|
||||||
if (!pdata) {
|
GFP_KERNEL);
|
||||||
error = -ENOMEM;
|
if (!pdata)
|
||||||
goto err_out;
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
|
pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
|
||||||
pdata->nbuttons = nbuttons;
|
pdata->nbuttons = nbuttons;
|
||||||
|
@ -619,7 +614,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
|
||||||
dev_err(dev,
|
dev_err(dev,
|
||||||
"Failed to get gpio flags, error: %d\n",
|
"Failed to get gpio flags, error: %d\n",
|
||||||
error);
|
error);
|
||||||
goto err_free_pdata;
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
button = &pdata->buttons[i++];
|
button = &pdata->buttons[i++];
|
||||||
|
@ -630,8 +625,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
|
||||||
if (of_property_read_u32(pp, "linux,code", &button->code)) {
|
if (of_property_read_u32(pp, "linux,code", &button->code)) {
|
||||||
dev_err(dev, "Button without keycode: 0x%x\n",
|
dev_err(dev, "Button without keycode: 0x%x\n",
|
||||||
button->gpio);
|
button->gpio);
|
||||||
error = -EINVAL;
|
return ERR_PTR(-EINVAL);
|
||||||
goto err_free_pdata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button->desc = of_get_property(pp, "label", NULL);
|
button->desc = of_get_property(pp, "label", NULL);
|
||||||
|
@ -646,17 +640,10 @@ gpio_keys_get_devtree_pdata(struct device *dev)
|
||||||
button->debounce_interval = 5;
|
button->debounce_interval = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdata->nbuttons == 0) {
|
if (pdata->nbuttons == 0)
|
||||||
error = -EINVAL;
|
return ERR_PTR(-EINVAL);
|
||||||
goto err_free_pdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pdata;
|
return pdata;
|
||||||
|
|
||||||
err_free_pdata:
|
|
||||||
kfree(pdata);
|
|
||||||
err_out:
|
|
||||||
return ERR_PTR(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct of_device_id gpio_keys_of_match[] = {
|
static struct of_device_id gpio_keys_of_match[] = {
|
||||||
|
@ -691,6 +678,7 @@ static int gpio_keys_probe(struct platform_device *pdev)
|
||||||
const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
|
const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
|
||||||
struct gpio_keys_drvdata *ddata;
|
struct gpio_keys_drvdata *ddata;
|
||||||
struct input_dev *input;
|
struct input_dev *input;
|
||||||
|
size_t size;
|
||||||
int i, error;
|
int i, error;
|
||||||
int wakeup = 0;
|
int wakeup = 0;
|
||||||
|
|
||||||
|
@ -700,14 +688,18 @@ static int gpio_keys_probe(struct platform_device *pdev)
|
||||||
return PTR_ERR(pdata);
|
return PTR_ERR(pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
|
size = sizeof(struct gpio_keys_drvdata) +
|
||||||
pdata->nbuttons * sizeof(struct gpio_button_data),
|
pdata->nbuttons * sizeof(struct gpio_button_data);
|
||||||
GFP_KERNEL);
|
ddata = devm_kzalloc(dev, size, GFP_KERNEL);
|
||||||
input = input_allocate_device();
|
if (!ddata) {
|
||||||
if (!ddata || !input) {
|
|
||||||
dev_err(dev, "failed to allocate state\n");
|
dev_err(dev, "failed to allocate state\n");
|
||||||
error = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto fail1;
|
}
|
||||||
|
|
||||||
|
input = devm_input_allocate_device(dev);
|
||||||
|
if (!input) {
|
||||||
|
dev_err(dev, "failed to allocate input device\n");
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddata->pdata = pdata;
|
ddata->pdata = pdata;
|
||||||
|
@ -768,20 +760,12 @@ static int gpio_keys_probe(struct platform_device *pdev)
|
||||||
while (--i >= 0)
|
while (--i >= 0)
|
||||||
gpio_remove_key(&ddata->data[i]);
|
gpio_remove_key(&ddata->data[i]);
|
||||||
|
|
||||||
fail1:
|
|
||||||
input_free_device(input);
|
|
||||||
kfree(ddata);
|
|
||||||
/* If we have no platform data, we allocated pdata dynamically. */
|
|
||||||
if (!dev_get_platdata(&pdev->dev))
|
|
||||||
kfree(pdata);
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gpio_keys_remove(struct platform_device *pdev)
|
static int gpio_keys_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
|
struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
|
||||||
struct input_dev *input = ddata->input;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
|
sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
|
||||||
|
@ -791,14 +775,6 @@ static int gpio_keys_remove(struct platform_device *pdev)
|
||||||
for (i = 0; i < ddata->pdata->nbuttons; i++)
|
for (i = 0; i < ddata->pdata->nbuttons; i++)
|
||||||
gpio_remove_key(&ddata->data[i]);
|
gpio_remove_key(&ddata->data[i]);
|
||||||
|
|
||||||
input_unregister_device(input);
|
|
||||||
|
|
||||||
/* If we have no platform data, we allocated pdata dynamically. */
|
|
||||||
if (!dev_get_platdata(&pdev->dev))
|
|
||||||
kfree(ddata->pdata);
|
|
||||||
|
|
||||||
kfree(ddata);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue