提交 1f9e1470 编写于 作者: F Fabio Estevam 提交者: Dmitry Torokhov

Input: twl6040-vibra - use devm functions

Using devm_regulator_bulk_get() and devm_input_allocate_device() can make
the code cleaner and smaller as we do not need to manually free resources
the error and remove paths.
Signed-off-by: NFabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
上级 c728601e
...@@ -262,7 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) ...@@ -262,7 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
struct vibra_info *info; struct vibra_info *info;
int vddvibl_uV = 0; int vddvibl_uV = 0;
int vddvibr_uV = 0; int vddvibr_uV = 0;
int ret; int error;
twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node, twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
"vibra"); "vibra");
...@@ -309,12 +309,12 @@ static int twl6040_vibra_probe(struct platform_device *pdev) ...@@ -309,12 +309,12 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
mutex_init(&info->mutex); mutex_init(&info->mutex);
ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, error = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
twl6040_vib_irq_handler, 0, twl6040_vib_irq_handler, 0,
"twl6040_irq_vib", info); "twl6040_irq_vib", info);
if (ret) { if (error) {
dev_err(info->dev, "VIB IRQ request failed: %d\n", ret); dev_err(info->dev, "VIB IRQ request failed: %d\n", error);
return ret; return error;
} }
info->supplies[0].supply = "vddvibl"; info->supplies[0].supply = "vddvibl";
...@@ -323,40 +323,40 @@ static int twl6040_vibra_probe(struct platform_device *pdev) ...@@ -323,40 +323,40 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
* When booted with Device tree the regulators are attached to the * When booted with Device tree the regulators are attached to the
* parent device (twl6040 MFD core) * parent device (twl6040 MFD core)
*/ */
ret = regulator_bulk_get(twl6040_core_dev, ARRAY_SIZE(info->supplies), error = devm_regulator_bulk_get(twl6040_core_dev,
ARRAY_SIZE(info->supplies),
info->supplies); info->supplies);
if (ret) { if (error) {
dev_err(info->dev, "couldn't get regulators %d\n", ret); dev_err(info->dev, "couldn't get regulators %d\n", error);
return ret; return error;
} }
if (vddvibl_uV) { if (vddvibl_uV) {
ret = regulator_set_voltage(info->supplies[0].consumer, error = regulator_set_voltage(info->supplies[0].consumer,
vddvibl_uV, vddvibl_uV); vddvibl_uV, vddvibl_uV);
if (ret) { if (error) {
dev_err(info->dev, "failed to set VDDVIBL volt %d\n", dev_err(info->dev, "failed to set VDDVIBL volt %d\n",
ret); error);
goto err_regulator; return error;
} }
} }
if (vddvibr_uV) { if (vddvibr_uV) {
ret = regulator_set_voltage(info->supplies[1].consumer, error = regulator_set_voltage(info->supplies[1].consumer,
vddvibr_uV, vddvibr_uV); vddvibr_uV, vddvibr_uV);
if (ret) { if (error) {
dev_err(info->dev, "failed to set VDDVIBR volt %d\n", dev_err(info->dev, "failed to set VDDVIBR volt %d\n",
ret); error);
goto err_regulator; return error;
} }
} }
INIT_WORK(&info->play_work, vibra_play_work); INIT_WORK(&info->play_work, vibra_play_work);
info->input_dev = input_allocate_device(); info->input_dev = devm_input_allocate_device(&pdev->dev);
if (info->input_dev == NULL) { if (!info->input_dev) {
dev_err(info->dev, "couldn't allocate input device\n"); dev_err(info->dev, "couldn't allocate input device\n");
ret = -ENOMEM; return -ENOMEM;
goto err_regulator;
} }
input_set_drvdata(info->input_dev, info); input_set_drvdata(info->input_dev, info);
...@@ -367,44 +367,25 @@ static int twl6040_vibra_probe(struct platform_device *pdev) ...@@ -367,44 +367,25 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
info->input_dev->close = twl6040_vibra_close; info->input_dev->close = twl6040_vibra_close;
__set_bit(FF_RUMBLE, info->input_dev->ffbit); __set_bit(FF_RUMBLE, info->input_dev->ffbit);
ret = input_ff_create_memless(info->input_dev, NULL, vibra_play); error = input_ff_create_memless(info->input_dev, NULL, vibra_play);
if (ret < 0) { if (error) {
dev_err(info->dev, "couldn't register vibrator to FF\n"); dev_err(info->dev, "couldn't register vibrator to FF\n");
goto err_ialloc; return error;
} }
ret = input_register_device(info->input_dev); error = input_register_device(info->input_dev);
if (ret < 0) { if (error) {
dev_err(info->dev, "couldn't register input device\n"); dev_err(info->dev, "couldn't register input device\n");
goto err_iff; return error;
} }
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
return 0;
err_iff:
input_ff_destroy(info->input_dev);
err_ialloc:
input_free_device(info->input_dev);
err_regulator:
regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
return ret;
}
static int twl6040_vibra_remove(struct platform_device *pdev)
{
struct vibra_info *info = platform_get_drvdata(pdev);
input_unregister_device(info->input_dev);
regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
return 0; return 0;
} }
static struct platform_driver twl6040_vibra_driver = { static struct platform_driver twl6040_vibra_driver = {
.probe = twl6040_vibra_probe, .probe = twl6040_vibra_probe,
.remove = twl6040_vibra_remove,
.driver = { .driver = {
.name = "twl6040-vibra", .name = "twl6040-vibra",
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册