aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorLaxman Dewangan <ldewangan@nvidia.com>2013-01-06 21:31:20 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-01-17 03:27:57 -0500
commit00eb81e56a38ffb7839e0e6262e26c20c617d2ab (patch)
tree8a37bdc1e074b03e979623c3ba3f75ac65a929d9 /drivers/input/keyboard
parent1c407a1b24debecccc42e5a2ae167f058dbb6fba (diff)
Input: tegra-kbc - use devm_* for resource allocation
Use devm_* for memory, clock, irq, input device allocation. This reduces code for freeing these resources. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/tegra-kbc.c105
1 files changed, 27 insertions, 78 deletions
diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
index f1d3ba0dafb2..f79993679070 100644
--- a/drivers/input/keyboard/tegra-kbc.c
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -618,7 +618,7 @@ static struct tegra_kbc_platform_data *tegra_kbc_dt_parse_pdata(
618 if (!np) 618 if (!np)
619 return NULL; 619 return NULL;
620 620
621 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 621 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
622 if (!pdata) 622 if (!pdata)
623 return NULL; 623 return NULL;
624 624
@@ -700,33 +700,36 @@ static int tegra_kbc_probe(struct platform_device *pdev)
700 if (!pdata) 700 if (!pdata)
701 pdata = tegra_kbc_dt_parse_pdata(pdev); 701 pdata = tegra_kbc_dt_parse_pdata(pdev);
702 702
703 if (!pdata) 703 if (!pdata) {
704 dev_err(&pdev->dev, "Platform data missing\n");
704 return -EINVAL; 705 return -EINVAL;
705
706 if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows)) {
707 err = -EINVAL;
708 goto err_free_pdata;
709 } 706 }
710 707
708 if (!tegra_kbc_check_pin_cfg(pdata, &pdev->dev, &num_rows))
709 return -EINVAL;
710
711 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 711 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
712 if (!res) { 712 if (!res) {
713 dev_err(&pdev->dev, "failed to get I/O memory\n"); 713 dev_err(&pdev->dev, "failed to get I/O memory\n");
714 err = -ENXIO; 714 return -ENXIO;
715 goto err_free_pdata;
716 } 715 }
717 716
718 irq = platform_get_irq(pdev, 0); 717 irq = platform_get_irq(pdev, 0);
719 if (irq < 0) { 718 if (irq < 0) {
720 dev_err(&pdev->dev, "failed to get keyboard IRQ\n"); 719 dev_err(&pdev->dev, "failed to get keyboard IRQ\n");
721 err = -ENXIO; 720 return -ENXIO;
722 goto err_free_pdata;
723 } 721 }
724 722
725 kbc = kzalloc(sizeof(*kbc), GFP_KERNEL); 723 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL);
726 input_dev = input_allocate_device(); 724 if (!kbc) {
727 if (!kbc || !input_dev) { 725 dev_err(&pdev->dev, "failed to alloc memory for kbc\n");
728 err = -ENOMEM; 726 return -ENOMEM;
729 goto err_free_mem; 727 }
728
729 input_dev = devm_input_allocate_device(&pdev->dev);
730 if (!input_dev) {
731 dev_err(&pdev->dev, "failed to allocate input device\n");
732 return -ENOMEM;
730 } 733 }
731 734
732 kbc->pdata = pdata; 735 kbc->pdata = pdata;
@@ -735,25 +738,16 @@ static int tegra_kbc_probe(struct platform_device *pdev)
735 spin_lock_init(&kbc->lock); 738 spin_lock_init(&kbc->lock);
736 setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc); 739 setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc);
737 740
738 res = request_mem_region(res->start, resource_size(res), pdev->name); 741 kbc->mmio = devm_request_and_ioremap(&pdev->dev, res);
739 if (!res) {
740 dev_err(&pdev->dev, "failed to request I/O memory\n");
741 err = -EBUSY;
742 goto err_free_mem;
743 }
744
745 kbc->mmio = ioremap(res->start, resource_size(res));
746 if (!kbc->mmio) { 742 if (!kbc->mmio) {
747 dev_err(&pdev->dev, "failed to remap I/O memory\n"); 743 dev_err(&pdev->dev, "Cannot request memregion/iomap address\n");
748 err = -ENXIO; 744 return -EBUSY;
749 goto err_free_mem_region;
750 } 745 }
751 746
752 kbc->clk = clk_get(&pdev->dev, NULL); 747 kbc->clk = devm_clk_get(&pdev->dev, NULL);
753 if (IS_ERR(kbc->clk)) { 748 if (IS_ERR(kbc->clk)) {
754 dev_err(&pdev->dev, "failed to get keyboard clock\n"); 749 dev_err(&pdev->dev, "failed to get keyboard clock\n");
755 err = PTR_ERR(kbc->clk); 750 return PTR_ERR(kbc->clk);
756 goto err_iounmap;
757 } 751 }
758 752
759 /* 753 /*
@@ -780,7 +774,7 @@ static int tegra_kbc_probe(struct platform_device *pdev)
780 err = tegra_kbd_setup_keymap(kbc); 774 err = tegra_kbd_setup_keymap(kbc);
781 if (err) { 775 if (err) {
782 dev_err(&pdev->dev, "failed to setup keymap\n"); 776 dev_err(&pdev->dev, "failed to setup keymap\n");
783 goto err_put_clk; 777 return err;
784 } 778 }
785 779
786 __set_bit(EV_REP, input_dev->evbit); 780 __set_bit(EV_REP, input_dev->evbit);
@@ -788,11 +782,11 @@ static int tegra_kbc_probe(struct platform_device *pdev)
788 782
789 input_set_drvdata(input_dev, kbc); 783 input_set_drvdata(input_dev, kbc);
790 784
791 err = request_irq(kbc->irq, tegra_kbc_isr, 785 err = devm_request_irq(&pdev->dev, kbc->irq, tegra_kbc_isr,
792 IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH, pdev->name, kbc); 786 IRQF_NO_SUSPEND | IRQF_TRIGGER_HIGH, pdev->name, kbc);
793 if (err) { 787 if (err) {
794 dev_err(&pdev->dev, "failed to request keyboard IRQ\n"); 788 dev_err(&pdev->dev, "failed to request keyboard IRQ\n");
795 goto err_put_clk; 789 return err;
796 } 790 }
797 791
798 disable_irq(kbc->irq); 792 disable_irq(kbc->irq);
@@ -800,57 +794,13 @@ static int tegra_kbc_probe(struct platform_device *pdev)
800 err = input_register_device(kbc->idev); 794 err = input_register_device(kbc->idev);
801 if (err) { 795 if (err) {
802 dev_err(&pdev->dev, "failed to register input device\n"); 796 dev_err(&pdev->dev, "failed to register input device\n");
803 goto err_free_irq; 797 return err;
804 } 798 }
805 799
806 platform_set_drvdata(pdev, kbc); 800 platform_set_drvdata(pdev, kbc);
807 device_init_wakeup(&pdev->dev, pdata->wakeup); 801 device_init_wakeup(&pdev->dev, pdata->wakeup);
808 802
809 return 0; 803 return 0;
810
811err_free_irq:
812 free_irq(kbc->irq, pdev);
813err_put_clk:
814 clk_put(kbc->clk);
815err_iounmap:
816 iounmap(kbc->mmio);
817err_free_mem_region:
818 release_mem_region(res->start, resource_size(res));
819err_free_mem:
820 input_free_device(input_dev);
821 kfree(kbc);
822err_free_pdata:
823 if (!pdev->dev.platform_data)
824 kfree(pdata);
825
826 return err;
827}
828
829static int tegra_kbc_remove(struct platform_device *pdev)
830{
831 struct tegra_kbc *kbc = platform_get_drvdata(pdev);
832 struct resource *res;
833
834 platform_set_drvdata(pdev, NULL);
835
836 free_irq(kbc->irq, pdev);
837 clk_put(kbc->clk);
838
839 input_unregister_device(kbc->idev);
840 iounmap(kbc->mmio);
841 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
842 release_mem_region(res->start, resource_size(res));
843
844 /*
845 * If we do not have platform data attached to the device we
846 * allocated it ourselves and thus need to free it.
847 */
848 if (!pdev->dev.platform_data)
849 kfree(kbc->pdata);
850
851 kfree(kbc);
852
853 return 0;
854} 804}
855 805
856#ifdef CONFIG_PM_SLEEP 806#ifdef CONFIG_PM_SLEEP
@@ -954,7 +904,6 @@ MODULE_DEVICE_TABLE(of, tegra_kbc_of_match);
954 904
955static struct platform_driver tegra_kbc_driver = { 905static struct platform_driver tegra_kbc_driver = {
956 .probe = tegra_kbc_probe, 906 .probe = tegra_kbc_probe,
957 .remove = tegra_kbc_remove,
958 .driver = { 907 .driver = {
959 .name = "tegra-kbc", 908 .name = "tegra-kbc",
960 .owner = THIS_MODULE, 909 .owner = THIS_MODULE,