diff options
author | Lothar Waßmann <LW@KARO-electronics.de> | 2014-01-16 19:26:55 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-01-20 23:29:21 -0500 |
commit | 02300bd6517e19bd8651c9e72c788749a442ae22 (patch) | |
tree | db7f77fcdff21398c10c1eca8d45a37a37632dcf /drivers/input | |
parent | c3c4d99485ea51cd354ed3cd955a8310703456b6 (diff) |
Input: edt_ft5x06 - use devm_* functions where appropriate
Simplify the error path and remove() function by using devm_*
functions for requesting gpios and irq and allocating the input
device.
Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/edt-ft5x06.c | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c index af0d68b703b7..412a85ec9ba5 100644 --- a/drivers/input/touchscreen/edt-ft5x06.c +++ b/drivers/input/touchscreen/edt-ft5x06.c | |||
@@ -623,8 +623,9 @@ static int edt_ft5x06_ts_reset(struct i2c_client *client, | |||
623 | 623 | ||
624 | if (gpio_is_valid(reset_pin)) { | 624 | if (gpio_is_valid(reset_pin)) { |
625 | /* this pulls reset down, enabling the low active reset */ | 625 | /* this pulls reset down, enabling the low active reset */ |
626 | error = gpio_request_one(reset_pin, GPIOF_OUT_INIT_LOW, | 626 | error = devm_gpio_request_one(&client->dev, reset_pin, |
627 | "edt-ft5x06 reset"); | 627 | GPIOF_OUT_INIT_LOW, |
628 | "edt-ft5x06 reset"); | ||
628 | if (error) { | 629 | if (error) { |
629 | dev_err(&client->dev, | 630 | dev_err(&client->dev, |
630 | "Failed to request GPIO %d as reset pin, error %d\n", | 631 | "Failed to request GPIO %d as reset pin, error %d\n", |
@@ -723,8 +724,8 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, | |||
723 | return error; | 724 | return error; |
724 | 725 | ||
725 | if (gpio_is_valid(pdata->irq_pin)) { | 726 | if (gpio_is_valid(pdata->irq_pin)) { |
726 | error = gpio_request_one(pdata->irq_pin, | 727 | error = devm_gpio_request_one(&client->dev, pdata->irq_pin, |
727 | GPIOF_IN, "edt-ft5x06 irq"); | 728 | GPIOF_IN, "edt-ft5x06 irq"); |
728 | if (error) { | 729 | if (error) { |
729 | dev_err(&client->dev, | 730 | dev_err(&client->dev, |
730 | "Failed to request GPIO %d, error %d\n", | 731 | "Failed to request GPIO %d, error %d\n", |
@@ -733,12 +734,16 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, | |||
733 | } | 734 | } |
734 | } | 735 | } |
735 | 736 | ||
736 | tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL); | 737 | tsdata = devm_kzalloc(&client->dev, sizeof(*tsdata), GFP_KERNEL); |
737 | input = input_allocate_device(); | 738 | if (!tsdata) { |
738 | if (!tsdata || !input) { | ||
739 | dev_err(&client->dev, "failed to allocate driver data.\n"); | 739 | dev_err(&client->dev, "failed to allocate driver data.\n"); |
740 | error = -ENOMEM; | 740 | return -ENOMEM; |
741 | goto err_free_mem; | 741 | } |
742 | |||
743 | input = devm_input_allocate_device(&client->dev); | ||
744 | if (!input) { | ||
745 | dev_err(&client->dev, "failed to allocate input device.\n"); | ||
746 | return -ENOMEM; | ||
742 | } | 747 | } |
743 | 748 | ||
744 | mutex_init(&tsdata->mutex); | 749 | mutex_init(&tsdata->mutex); |
@@ -749,7 +754,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, | |||
749 | error = edt_ft5x06_ts_identify(client, tsdata->name, fw_version); | 754 | error = edt_ft5x06_ts_identify(client, tsdata->name, fw_version); |
750 | if (error) { | 755 | if (error) { |
751 | dev_err(&client->dev, "touchscreen probe failed\n"); | 756 | dev_err(&client->dev, "touchscreen probe failed\n"); |
752 | goto err_free_mem; | 757 | return error; |
753 | } | 758 | } |
754 | 759 | ||
755 | edt_ft5x06_ts_get_defaults(tsdata, pdata); | 760 | edt_ft5x06_ts_get_defaults(tsdata, pdata); |
@@ -776,27 +781,30 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, | |||
776 | error = input_mt_init_slots(input, MAX_SUPPORT_POINTS, 0); | 781 | error = input_mt_init_slots(input, MAX_SUPPORT_POINTS, 0); |
777 | if (error) { | 782 | if (error) { |
778 | dev_err(&client->dev, "Unable to init MT slots.\n"); | 783 | dev_err(&client->dev, "Unable to init MT slots.\n"); |
779 | goto err_free_mem; | 784 | return error; |
780 | } | 785 | } |
781 | 786 | ||
782 | input_set_drvdata(input, tsdata); | 787 | input_set_drvdata(input, tsdata); |
783 | i2c_set_clientdata(client, tsdata); | 788 | i2c_set_clientdata(client, tsdata); |
784 | 789 | ||
785 | error = request_threaded_irq(client->irq, NULL, edt_ft5x06_ts_isr, | 790 | error = devm_request_threaded_irq(&client->dev, client->irq, |
786 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 791 | NULL, edt_ft5x06_ts_isr, |
787 | client->name, tsdata); | 792 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
793 | client->name, tsdata); | ||
788 | if (error) { | 794 | if (error) { |
789 | dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); | 795 | dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); |
790 | goto err_free_mem; | 796 | return error; |
791 | } | 797 | } |
792 | 798 | ||
793 | error = sysfs_create_group(&client->dev.kobj, &edt_ft5x06_attr_group); | 799 | error = sysfs_create_group(&client->dev.kobj, &edt_ft5x06_attr_group); |
794 | if (error) | 800 | if (error) |
795 | goto err_free_irq; | 801 | return error; |
796 | 802 | ||
797 | error = input_register_device(input); | 803 | error = input_register_device(input); |
798 | if (error) | 804 | if (error) { |
799 | goto err_remove_attrs; | 805 | sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); |
806 | return error; | ||
807 | } | ||
800 | 808 | ||
801 | edt_ft5x06_ts_prepare_debugfs(tsdata, dev_driver_string(&client->dev)); | 809 | edt_ft5x06_ts_prepare_debugfs(tsdata, dev_driver_string(&client->dev)); |
802 | device_init_wakeup(&client->dev, 1); | 810 | device_init_wakeup(&client->dev, 1); |
@@ -806,40 +814,15 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, | |||
806 | pdata->irq_pin, pdata->reset_pin); | 814 | pdata->irq_pin, pdata->reset_pin); |
807 | 815 | ||
808 | return 0; | 816 | return 0; |
809 | |||
810 | err_remove_attrs: | ||
811 | sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); | ||
812 | err_free_irq: | ||
813 | free_irq(client->irq, tsdata); | ||
814 | err_free_mem: | ||
815 | input_free_device(input); | ||
816 | kfree(tsdata); | ||
817 | |||
818 | if (gpio_is_valid(pdata->irq_pin)) | ||
819 | gpio_free(pdata->irq_pin); | ||
820 | |||
821 | return error; | ||
822 | } | 817 | } |
823 | 818 | ||
824 | static int edt_ft5x06_ts_remove(struct i2c_client *client) | 819 | static int edt_ft5x06_ts_remove(struct i2c_client *client) |
825 | { | 820 | { |
826 | const struct edt_ft5x06_platform_data *pdata = | ||
827 | dev_get_platdata(&client->dev); | ||
828 | struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client); | 821 | struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client); |
829 | 822 | ||
830 | edt_ft5x06_ts_teardown_debugfs(tsdata); | 823 | edt_ft5x06_ts_teardown_debugfs(tsdata); |
831 | sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); | 824 | sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); |
832 | 825 | ||
833 | free_irq(client->irq, tsdata); | ||
834 | input_unregister_device(tsdata->input); | ||
835 | |||
836 | if (gpio_is_valid(pdata->irq_pin)) | ||
837 | gpio_free(pdata->irq_pin); | ||
838 | if (gpio_is_valid(pdata->reset_pin)) | ||
839 | gpio_free(pdata->reset_pin); | ||
840 | |||
841 | kfree(tsdata); | ||
842 | |||
843 | return 0; | 826 | return 0; |
844 | } | 827 | } |
845 | 828 | ||