Commit 12a5a8fd authored by Stephen Boyd's avatar Stephen Boyd Committed by Dmitry Torokhov

Input: pm8xxx-vibrator - switch to using managed resources

Simplify the error paths and reduce the lines of code in this
driver by using the devm_* APIs.
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 9222d806
...@@ -186,13 +186,13 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) ...@@ -186,13 +186,13 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
int error; int error;
u8 val; u8 val;
vib = kzalloc(sizeof(*vib), GFP_KERNEL); vib = devm_kzalloc(&pdev->dev, sizeof(*vib), GFP_KERNEL);
input_dev = input_allocate_device(); if (!vib)
if (!vib || !input_dev) { return -ENOMEM;
dev_err(&pdev->dev, "couldn't allocate memory\n");
error = -ENOMEM; input_dev = devm_input_allocate_device(&pdev->dev);
goto err_free_mem; if (!input_dev)
} return -ENOMEM;
INIT_WORK(&vib->work, pm8xxx_work_handler); INIT_WORK(&vib->work, pm8xxx_work_handler);
vib->dev = &pdev->dev; vib->dev = &pdev->dev;
...@@ -201,17 +201,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) ...@@ -201,17 +201,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
/* operate in manual mode */ /* operate in manual mode */
error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV); error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV);
if (error < 0) if (error < 0)
goto err_free_mem; return error;
val &= ~VIB_DRV_EN_MANUAL_MASK; val &= ~VIB_DRV_EN_MANUAL_MASK;
error = pm8xxx_vib_write_u8(vib, val, VIB_DRV); error = pm8xxx_vib_write_u8(vib, val, VIB_DRV);
if (error < 0) if (error < 0)
goto err_free_mem; return error;
vib->reg_vib_drv = val; vib->reg_vib_drv = val;
input_dev->name = "pm8xxx_vib_ffmemless"; input_dev->name = "pm8xxx_vib_ffmemless";
input_dev->id.version = 1; input_dev->id.version = 1;
input_dev->dev.parent = &pdev->dev;
input_dev->close = pm8xxx_vib_close; input_dev->close = pm8xxx_vib_close;
input_set_drvdata(input_dev, vib); input_set_drvdata(input_dev, vib);
input_set_capability(vib->vib_input_dev, EV_FF, FF_RUMBLE); input_set_capability(vib->vib_input_dev, EV_FF, FF_RUMBLE);
...@@ -221,35 +221,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev) ...@@ -221,35 +221,17 @@ static int pm8xxx_vib_probe(struct platform_device *pdev)
if (error) { if (error) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"couldn't register vibrator as FF device\n"); "couldn't register vibrator as FF device\n");
goto err_free_mem; return error;
} }
error = input_register_device(input_dev); error = input_register_device(input_dev);
if (error) { if (error) {
dev_err(&pdev->dev, "couldn't register input device\n"); dev_err(&pdev->dev, "couldn't register input device\n");
goto err_destroy_memless; return error;
} }
platform_set_drvdata(pdev, vib); platform_set_drvdata(pdev, vib);
return 0; return 0;
err_destroy_memless:
input_ff_destroy(input_dev);
err_free_mem:
input_free_device(input_dev);
kfree(vib);
return error;
}
static int pm8xxx_vib_remove(struct platform_device *pdev)
{
struct pm8xxx_vib *vib = platform_get_drvdata(pdev);
input_unregister_device(vib->vib_input_dev);
kfree(vib);
return 0;
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
...@@ -268,7 +250,6 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_vib_pm_ops, pm8xxx_vib_suspend, NULL); ...@@ -268,7 +250,6 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_vib_pm_ops, pm8xxx_vib_suspend, NULL);
static struct platform_driver pm8xxx_vib_driver = { static struct platform_driver pm8xxx_vib_driver = {
.probe = pm8xxx_vib_probe, .probe = pm8xxx_vib_probe,
.remove = pm8xxx_vib_remove,
.driver = { .driver = {
.name = "pm8xxx-vib", .name = "pm8xxx-vib",
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
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