Commit 02300bd6517e19bd8651c9e72c788749a442ae22
Committed by
Dmitry Torokhov
1 parent
c3c4d99485
Exists in
master
and in
16 other branches
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>
Showing 1 changed file with 26 additions and 43 deletions Side-by-side Diff
drivers/input/touchscreen/edt-ft5x06.c
... | ... | @@ -623,8 +623,9 @@ |
623 | 623 | |
624 | 624 | if (gpio_is_valid(reset_pin)) { |
625 | 625 | /* this pulls reset down, enabling the low active reset */ |
626 | - error = gpio_request_one(reset_pin, GPIOF_OUT_INIT_LOW, | |
627 | - "edt-ft5x06 reset"); | |
626 | + error = devm_gpio_request_one(&client->dev, reset_pin, | |
627 | + GPIOF_OUT_INIT_LOW, | |
628 | + "edt-ft5x06 reset"); | |
628 | 629 | if (error) { |
629 | 630 | dev_err(&client->dev, |
630 | 631 | "Failed to request GPIO %d as reset pin, error %d\n", |
... | ... | @@ -723,8 +724,8 @@ |
723 | 724 | return error; |
724 | 725 | |
725 | 726 | if (gpio_is_valid(pdata->irq_pin)) { |
726 | - error = gpio_request_one(pdata->irq_pin, | |
727 | - GPIOF_IN, "edt-ft5x06 irq"); | |
727 | + error = devm_gpio_request_one(&client->dev, pdata->irq_pin, | |
728 | + GPIOF_IN, "edt-ft5x06 irq"); | |
728 | 729 | if (error) { |
729 | 730 | dev_err(&client->dev, |
730 | 731 | "Failed to request GPIO %d, error %d\n", |
731 | 732 | |
732 | 733 | |
... | ... | @@ -733,14 +734,18 @@ |
733 | 734 | } |
734 | 735 | } |
735 | 736 | |
736 | - tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL); | |
737 | - input = input_allocate_device(); | |
738 | - if (!tsdata || !input) { | |
737 | + tsdata = devm_kzalloc(&client->dev, sizeof(*tsdata), GFP_KERNEL); | |
738 | + if (!tsdata) { | |
739 | 739 | dev_err(&client->dev, "failed to allocate driver data.\n"); |
740 | - error = -ENOMEM; | |
741 | - goto err_free_mem; | |
740 | + return -ENOMEM; | |
742 | 741 | } |
743 | 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; | |
747 | + } | |
748 | + | |
744 | 749 | mutex_init(&tsdata->mutex); |
745 | 750 | tsdata->client = client; |
746 | 751 | tsdata->input = input; |
... | ... | @@ -749,7 +754,7 @@ |
749 | 754 | error = edt_ft5x06_ts_identify(client, tsdata->name, fw_version); |
750 | 755 | if (error) { |
751 | 756 | dev_err(&client->dev, "touchscreen probe failed\n"); |
752 | - goto err_free_mem; | |
757 | + return error; | |
753 | 758 | } |
754 | 759 | |
755 | 760 | edt_ft5x06_ts_get_defaults(tsdata, pdata); |
756 | 761 | |
757 | 762 | |
758 | 763 | |
759 | 764 | |
... | ... | @@ -776,27 +781,30 @@ |
776 | 781 | error = input_mt_init_slots(input, MAX_SUPPORT_POINTS, 0); |
777 | 782 | if (error) { |
778 | 783 | dev_err(&client->dev, "Unable to init MT slots.\n"); |
779 | - goto err_free_mem; | |
784 | + return error; | |
780 | 785 | } |
781 | 786 | |
782 | 787 | input_set_drvdata(input, tsdata); |
783 | 788 | i2c_set_clientdata(client, tsdata); |
784 | 789 | |
785 | - error = request_threaded_irq(client->irq, NULL, edt_ft5x06_ts_isr, | |
786 | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | |
787 | - client->name, tsdata); | |
790 | + error = devm_request_threaded_irq(&client->dev, client->irq, | |
791 | + NULL, edt_ft5x06_ts_isr, | |
792 | + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | |
793 | + client->name, tsdata); | |
788 | 794 | if (error) { |
789 | 795 | dev_err(&client->dev, "Unable to request touchscreen IRQ.\n"); |
790 | - goto err_free_mem; | |
796 | + return error; | |
791 | 797 | } |
792 | 798 | |
793 | 799 | error = sysfs_create_group(&client->dev.kobj, &edt_ft5x06_attr_group); |
794 | 800 | if (error) |
795 | - goto err_free_irq; | |
801 | + return error; | |
796 | 802 | |
797 | 803 | error = input_register_device(input); |
798 | - if (error) | |
799 | - goto err_remove_attrs; | |
804 | + if (error) { | |
805 | + sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); | |
806 | + return error; | |
807 | + } | |
800 | 808 | |
801 | 809 | edt_ft5x06_ts_prepare_debugfs(tsdata, dev_driver_string(&client->dev)); |
802 | 810 | device_init_wakeup(&client->dev, 1); |
803 | 811 | |
804 | 812 | |
... | ... | @@ -806,39 +814,14 @@ |
806 | 814 | pdata->irq_pin, pdata->reset_pin); |
807 | 815 | |
808 | 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 | 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 | 821 | struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client); |
829 | 822 | |
830 | 823 | edt_ft5x06_ts_teardown_debugfs(tsdata); |
831 | 824 | sysfs_remove_group(&client->dev.kobj, &edt_ft5x06_attr_group); |
832 | - | |
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 | 825 | |
843 | 826 | return 0; |
844 | 827 | } |