aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorJulia Lawall <Julia.Lawall@lip6.fr>2012-07-31 09:09:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-08-16 15:03:19 -0400
commit390d75c1287bf68c2e29226bf8eb10ae6a08c380 (patch)
tree67b5ac8e5acfabe5c7de9bc6142bd618ace0d042 /drivers/iio
parentd16f6dbddbd7a2ac40e090da1e6bb7dd9b5a1dcb (diff)
drivers/iio/adc/at91_adc.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver detaches. This patch uses these functions for data that is allocated in the probe function of a platform device and is only freed in the remove function. The call to platform_get_resource(pdev, IORESOURCE_MEM, 0) is moved coser to the call to devm_request_and_ioremap, which is th first use of the result of platform_get_resource. This does not use devm_request_irq to ensure that free_irq is executed before its idev argument is freed. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/at91_adc.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index f61780a02374..98c96f90c88b 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -545,13 +545,6 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
545 goto error_free_device; 545 goto error_free_device;
546 } 546 }
547 547
548 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
549 if (!res) {
550 dev_err(&pdev->dev, "No resource defined\n");
551 ret = -ENXIO;
552 goto error_ret;
553 }
554
555 platform_set_drvdata(pdev, idev); 548 platform_set_drvdata(pdev, idev);
556 549
557 idev->dev.parent = &pdev->dev; 550 idev->dev.parent = &pdev->dev;
@@ -566,18 +559,12 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
566 goto error_free_device; 559 goto error_free_device;
567 } 560 }
568 561
569 if (!request_mem_region(res->start, resource_size(res), 562 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
570 "AT91 adc registers")) {
571 dev_err(&pdev->dev, "Resources are unavailable.\n");
572 ret = -EBUSY;
573 goto error_free_device;
574 }
575 563
576 st->reg_base = ioremap(res->start, resource_size(res)); 564 st->reg_base = devm_request_and_ioremap(&pdev->dev, res);
577 if (!st->reg_base) { 565 if (!st->reg_base) {
578 dev_err(&pdev->dev, "Failed to map registers.\n");
579 ret = -ENOMEM; 566 ret = -ENOMEM;
580 goto error_release_mem; 567 goto error_free_device;
581 } 568 }
582 569
583 /* 570 /*
@@ -592,10 +579,10 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
592 idev); 579 idev);
593 if (ret) { 580 if (ret) {
594 dev_err(&pdev->dev, "Failed to allocate IRQ.\n"); 581 dev_err(&pdev->dev, "Failed to allocate IRQ.\n");
595 goto error_unmap_reg; 582 goto error_free_device;
596 } 583 }
597 584
598 st->clk = clk_get(&pdev->dev, "adc_clk"); 585 st->clk = devm_clk_get(&pdev->dev, "adc_clk");
599 if (IS_ERR(st->clk)) { 586 if (IS_ERR(st->clk)) {
600 dev_err(&pdev->dev, "Failed to get the clock.\n"); 587 dev_err(&pdev->dev, "Failed to get the clock.\n");
601 ret = PTR_ERR(st->clk); 588 ret = PTR_ERR(st->clk);
@@ -605,7 +592,7 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
605 ret = clk_prepare(st->clk); 592 ret = clk_prepare(st->clk);
606 if (ret) { 593 if (ret) {
607 dev_err(&pdev->dev, "Could not prepare the clock.\n"); 594 dev_err(&pdev->dev, "Could not prepare the clock.\n");
608 goto error_free_clk; 595 goto error_free_irq;
609 } 596 }
610 597
611 ret = clk_enable(st->clk); 598 ret = clk_enable(st->clk);
@@ -614,7 +601,7 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
614 goto error_unprepare_clk; 601 goto error_unprepare_clk;
615 } 602 }
616 603
617 st->adc_clk = clk_get(&pdev->dev, "adc_op_clk"); 604 st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
618 if (IS_ERR(st->adc_clk)) { 605 if (IS_ERR(st->adc_clk)) {
619 dev_err(&pdev->dev, "Failed to get the ADC clock.\n"); 606 dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
620 ret = PTR_ERR(st->clk); 607 ret = PTR_ERR(st->clk);
@@ -624,7 +611,7 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
624 ret = clk_prepare(st->adc_clk); 611 ret = clk_prepare(st->adc_clk);
625 if (ret) { 612 if (ret) {
626 dev_err(&pdev->dev, "Could not prepare the ADC clock.\n"); 613 dev_err(&pdev->dev, "Could not prepare the ADC clock.\n");
627 goto error_free_adc_clk; 614 goto error_disable_clk;
628 } 615 }
629 616
630 ret = clk_enable(st->adc_clk); 617 ret = clk_enable(st->adc_clk);
@@ -697,20 +684,12 @@ error_disable_adc_clk:
697 clk_disable(st->adc_clk); 684 clk_disable(st->adc_clk);
698error_unprepare_adc_clk: 685error_unprepare_adc_clk:
699 clk_unprepare(st->adc_clk); 686 clk_unprepare(st->adc_clk);
700error_free_adc_clk:
701 clk_put(st->adc_clk);
702error_disable_clk: 687error_disable_clk:
703 clk_disable(st->clk); 688 clk_disable(st->clk);
704error_unprepare_clk: 689error_unprepare_clk:
705 clk_unprepare(st->clk); 690 clk_unprepare(st->clk);
706error_free_clk:
707 clk_put(st->clk);
708error_free_irq: 691error_free_irq:
709 free_irq(st->irq, idev); 692 free_irq(st->irq, idev);
710error_unmap_reg:
711 iounmap(st->reg_base);
712error_release_mem:
713 release_mem_region(res->start, resource_size(res));
714error_free_device: 693error_free_device:
715 iio_device_free(idev); 694 iio_device_free(idev);
716error_ret: 695error_ret:
@@ -720,20 +699,15 @@ error_ret:
720static int __devexit at91_adc_remove(struct platform_device *pdev) 699static int __devexit at91_adc_remove(struct platform_device *pdev)
721{ 700{
722 struct iio_dev *idev = platform_get_drvdata(pdev); 701 struct iio_dev *idev = platform_get_drvdata(pdev);
723 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
724 struct at91_adc_state *st = iio_priv(idev); 702 struct at91_adc_state *st = iio_priv(idev);
725 703
726 iio_device_unregister(idev); 704 iio_device_unregister(idev);
727 at91_adc_trigger_remove(idev); 705 at91_adc_trigger_remove(idev);
728 at91_adc_buffer_remove(idev); 706 at91_adc_buffer_remove(idev);
729 clk_disable_unprepare(st->adc_clk); 707 clk_disable_unprepare(st->adc_clk);
730 clk_put(st->adc_clk);
731 clk_disable(st->clk); 708 clk_disable(st->clk);
732 clk_unprepare(st->clk); 709 clk_unprepare(st->clk);
733 clk_put(st->clk);
734 free_irq(st->irq, idev); 710 free_irq(st->irq, idev);
735 iounmap(st->reg_base);
736 release_mem_region(res->start, resource_size(res));
737 iio_device_free(idev); 711 iio_device_free(idev);
738 712
739 return 0; 713 return 0;