diff options
author | Sebastian Reichel <sre@kernel.org> | 2014-04-26 00:50:21 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-05-14 19:39:50 -0400 |
commit | 99e8325f55f2dfea32430fd71a546485a2aedbae (patch) | |
tree | 4d7c07bf1508104f1bdb83d57c9f594071cdc054 /drivers/input/touchscreen/tsc2005.c | |
parent | 6e51c857b290b694487474b2d2d85239f232f7e4 (diff) |
Input: tsc2005 - convert driver to use devm_*
Simplify the driver by using managed resources for memory allocation of
internal structure, input device allocation and irq request.
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen/tsc2005.c')
-rw-r--r-- | drivers/input/touchscreen/tsc2005.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c index 520e673687ff..d981e49368ad 100644 --- a/drivers/input/touchscreen/tsc2005.c +++ b/drivers/input/touchscreen/tsc2005.c | |||
@@ -604,12 +604,13 @@ static int tsc2005_probe(struct spi_device *spi) | |||
604 | if (error) | 604 | if (error) |
605 | return error; | 605 | return error; |
606 | 606 | ||
607 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); | 607 | ts = devm_kzalloc(&spi->dev, sizeof(*ts), GFP_KERNEL); |
608 | input_dev = input_allocate_device(); | 608 | if (!ts) |
609 | if (!ts || !input_dev) { | 609 | return -ENOMEM; |
610 | error = -ENOMEM; | 610 | |
611 | goto err_free_mem; | 611 | input_dev = devm_input_allocate_device(&spi->dev); |
612 | } | 612 | if (!input_dev) |
613 | return -ENOMEM; | ||
613 | 614 | ||
614 | ts->spi = spi; | 615 | ts->spi = spi; |
615 | ts->idev = input_dev; | 616 | ts->idev = input_dev; |
@@ -649,12 +650,13 @@ static int tsc2005_probe(struct spi_device *spi) | |||
649 | /* Ensure the touchscreen is off */ | 650 | /* Ensure the touchscreen is off */ |
650 | tsc2005_stop_scan(ts); | 651 | tsc2005_stop_scan(ts); |
651 | 652 | ||
652 | error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread, | 653 | error = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, |
653 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | 654 | tsc2005_irq_thread, |
654 | "tsc2005", ts); | 655 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
656 | "tsc2005", ts); | ||
655 | if (error) { | 657 | if (error) { |
656 | dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); | 658 | dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); |
657 | goto err_free_mem; | 659 | return error; |
658 | } | 660 | } |
659 | 661 | ||
660 | spi_set_drvdata(spi, ts); | 662 | spi_set_drvdata(spi, ts); |
@@ -662,7 +664,7 @@ static int tsc2005_probe(struct spi_device *spi) | |||
662 | if (error) { | 664 | if (error) { |
663 | dev_err(&spi->dev, | 665 | dev_err(&spi->dev, |
664 | "Failed to create sysfs attributes, err: %d\n", error); | 666 | "Failed to create sysfs attributes, err: %d\n", error); |
665 | goto err_clear_drvdata; | 667 | return error; |
666 | } | 668 | } |
667 | 669 | ||
668 | error = input_register_device(ts->idev); | 670 | error = input_register_device(ts->idev); |
@@ -677,23 +679,12 @@ static int tsc2005_probe(struct spi_device *spi) | |||
677 | 679 | ||
678 | err_remove_sysfs: | 680 | err_remove_sysfs: |
679 | sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); | 681 | sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); |
680 | err_clear_drvdata: | ||
681 | free_irq(spi->irq, ts); | ||
682 | err_free_mem: | ||
683 | input_free_device(input_dev); | ||
684 | kfree(ts); | ||
685 | return error; | 682 | return error; |
686 | } | 683 | } |
687 | 684 | ||
688 | static int tsc2005_remove(struct spi_device *spi) | 685 | static int tsc2005_remove(struct spi_device *spi) |
689 | { | 686 | { |
690 | struct tsc2005 *ts = spi_get_drvdata(spi); | 687 | sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); |
691 | |||
692 | sysfs_remove_group(&ts->spi->dev.kobj, &tsc2005_attr_group); | ||
693 | |||
694 | free_irq(ts->spi->irq, ts); | ||
695 | input_unregister_device(ts->idev); | ||
696 | kfree(ts); | ||
697 | 688 | ||
698 | return 0; | 689 | return 0; |
699 | } | 690 | } |