Commit aaa4f2a7 authored by Viresh Kumar's avatar Viresh Kumar Committed by Dmitry Torokhov

Input: stmpe-keyboard - switch to using managed resources

This patch frees stmpe-keyboard driver from burden of freeing resources :)
devm_* derivatives of multiple routines are used while allocating resources,
which would be freed automatically by kernel.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 6102752e
...@@ -260,10 +260,10 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad) ...@@ -260,10 +260,10 @@ static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
static int __devinit stmpe_keypad_probe(struct platform_device *pdev) static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
{ {
struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
struct stmpe_keypad_platform_data *plat; const struct stmpe_keypad_platform_data *plat;
struct stmpe_keypad *keypad; struct stmpe_keypad *keypad;
struct input_dev *input; struct input_dev *input;
int ret; int error;
int irq; int irq;
int i; int i;
...@@ -275,26 +275,25 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev) ...@@ -275,26 +275,25 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
if (irq < 0) if (irq < 0)
return irq; return irq;
keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL); keypad = devm_kzalloc(&pdev->dev, sizeof(struct stmpe_keypad),
GFP_KERNEL);
if (!keypad) if (!keypad)
return -ENOMEM; return -ENOMEM;
input = input_allocate_device(); input = devm_input_allocate_device(&pdev->dev);
if (!input) { if (!input)
ret = -ENOMEM; return -ENOMEM;
goto out_freekeypad;
}
input->name = "STMPE keypad"; input->name = "STMPE keypad";
input->id.bustype = BUS_I2C; input->id.bustype = BUS_I2C;
input->dev.parent = &pdev->dev; input->dev.parent = &pdev->dev;
ret = matrix_keypad_build_keymap(plat->keymap_data, NULL, error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
STMPE_KEYPAD_MAX_ROWS, STMPE_KEYPAD_MAX_ROWS,
STMPE_KEYPAD_MAX_COLS, STMPE_KEYPAD_MAX_COLS,
keypad->keymap, input); keypad->keymap, input);
if (ret) if (error)
goto out_freeinput; return error;
input_set_capability(input, EV_MSC, MSC_SCAN); input_set_capability(input, EV_MSC, MSC_SCAN);
if (!plat->no_autorepeat) if (!plat->no_autorepeat)
...@@ -312,50 +311,35 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev) ...@@ -312,50 +311,35 @@ static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
keypad->input = input; keypad->input = input;
keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
ret = stmpe_keypad_chip_init(keypad); error = stmpe_keypad_chip_init(keypad);
if (ret < 0) if (error < 0)
goto out_freeinput; return error;
ret = input_register_device(input); error = devm_request_threaded_irq(&pdev->dev, irq,
if (ret) { NULL, stmpe_keypad_irq,
dev_err(&pdev->dev, IRQF_ONESHOT, "stmpe-keypad", keypad);
"unable to register input device: %d\n", ret); if (error) {
goto out_freeinput; dev_err(&pdev->dev, "unable to get irq: %d\n", error);
return error;
} }
ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT, error = input_register_device(input);
"stmpe-keypad", keypad); if (error) {
if (ret) { dev_err(&pdev->dev,
dev_err(&pdev->dev, "unable to get irq: %d\n", ret); "unable to register input device: %d\n", error);
goto out_unregisterinput; return error;
} }
platform_set_drvdata(pdev, keypad); platform_set_drvdata(pdev, keypad);
return 0; return 0;
out_unregisterinput:
input_unregister_device(input);
input = NULL;
out_freeinput:
input_free_device(input);
out_freekeypad:
kfree(keypad);
return ret;
} }
static int __devexit stmpe_keypad_remove(struct platform_device *pdev) static int __devexit stmpe_keypad_remove(struct platform_device *pdev)
{ {
struct stmpe_keypad *keypad = platform_get_drvdata(pdev); struct stmpe_keypad *keypad = platform_get_drvdata(pdev);
struct stmpe *stmpe = keypad->stmpe;
int irq = platform_get_irq(pdev, 0);
stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD);
free_irq(irq, keypad); stmpe_disable(keypad->stmpe, STMPE_BLOCK_KEYPAD);
input_unregister_device(keypad->input);
platform_set_drvdata(pdev, NULL);
kfree(keypad);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment