diff options
author | Julia Lawall <julia.lawall@lip6.fr> | 2011-12-29 11:51:22 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-02 08:07:56 -0500 |
commit | cd0ff7eff08e7daeba278cf58392aac519edff60 (patch) | |
tree | cd9a46b14538b8f4d01f128366df7b1530d30e77 /sound/soc/davinci | |
parent | 96d31e2b128e2adc7c4907e259a2d58b2f5edb32 (diff) |
ASoC: davinci-i2s.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses devm_kzalloc, devm_request_mem_region and
devm_ioremap for data that is allocated in the probe function of a platform
device and is only freed in the remove function.
In this case, the original code did not contain a call to iounmap, nor does
one appear anywhere else in the file. I have assumed that it is safe to
use devm_ioremap for the allocation in any case.
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/davinci')
-rw-r--r-- | sound/soc/davinci/davinci-i2s.c | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c index ec187100367e..0a74b9587a2c 100644 --- a/sound/soc/davinci/davinci-i2s.c +++ b/sound/soc/davinci/davinci-i2s.c | |||
@@ -661,18 +661,18 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
661 | return -ENODEV; | 661 | return -ENODEV; |
662 | } | 662 | } |
663 | 663 | ||
664 | ioarea = request_mem_region(mem->start, resource_size(mem), | 664 | ioarea = devm_request_mem_region(&pdev->dev, mem->start, |
665 | pdev->name); | 665 | resource_size(mem), |
666 | pdev->name); | ||
666 | if (!ioarea) { | 667 | if (!ioarea) { |
667 | dev_err(&pdev->dev, "McBSP region already claimed\n"); | 668 | dev_err(&pdev->dev, "McBSP region already claimed\n"); |
668 | return -EBUSY; | 669 | return -EBUSY; |
669 | } | 670 | } |
670 | 671 | ||
671 | dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL); | 672 | dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcbsp_dev), |
672 | if (!dev) { | 673 | GFP_KERNEL); |
673 | ret = -ENOMEM; | 674 | if (!dev) |
674 | goto err_release_region; | 675 | return -ENOMEM; |
675 | } | ||
676 | if (pdata) { | 676 | if (pdata) { |
677 | dev->enable_channel_combine = pdata->enable_channel_combine; | 677 | dev->enable_channel_combine = pdata->enable_channel_combine; |
678 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size = | 678 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size = |
@@ -691,13 +691,11 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
691 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].ram_chan_q = ram_chan_q; | 691 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].ram_chan_q = ram_chan_q; |
692 | 692 | ||
693 | dev->clk = clk_get(&pdev->dev, NULL); | 693 | dev->clk = clk_get(&pdev->dev, NULL); |
694 | if (IS_ERR(dev->clk)) { | 694 | if (IS_ERR(dev->clk)) |
695 | ret = -ENODEV; | 695 | return -ENODEV; |
696 | goto err_free_mem; | ||
697 | } | ||
698 | clk_enable(dev->clk); | 696 | clk_enable(dev->clk); |
699 | 697 | ||
700 | dev->base = ioremap(mem->start, resource_size(mem)); | 698 | dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
701 | if (!dev->base) { | 699 | if (!dev->base) { |
702 | dev_err(&pdev->dev, "ioremap failed\n"); | 700 | dev_err(&pdev->dev, "ioremap failed\n"); |
703 | ret = -ENOMEM; | 701 | ret = -ENOMEM; |
@@ -715,7 +713,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
715 | if (!res) { | 713 | if (!res) { |
716 | dev_err(&pdev->dev, "no DMA resource\n"); | 714 | dev_err(&pdev->dev, "no DMA resource\n"); |
717 | ret = -ENXIO; | 715 | ret = -ENXIO; |
718 | goto err_iounmap; | 716 | goto err_release_clk; |
719 | } | 717 | } |
720 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start; | 718 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start; |
721 | 719 | ||
@@ -723,7 +721,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
723 | if (!res) { | 721 | if (!res) { |
724 | dev_err(&pdev->dev, "no DMA resource\n"); | 722 | dev_err(&pdev->dev, "no DMA resource\n"); |
725 | ret = -ENXIO; | 723 | ret = -ENXIO; |
726 | goto err_iounmap; | 724 | goto err_release_clk; |
727 | } | 725 | } |
728 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; | 726 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; |
729 | dev->dev = &pdev->dev; | 727 | dev->dev = &pdev->dev; |
@@ -732,35 +730,24 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
732 | 730 | ||
733 | ret = snd_soc_register_dai(&pdev->dev, &davinci_i2s_dai); | 731 | ret = snd_soc_register_dai(&pdev->dev, &davinci_i2s_dai); |
734 | if (ret != 0) | 732 | if (ret != 0) |
735 | goto err_iounmap; | 733 | goto err_release_clk; |
736 | 734 | ||
737 | return 0; | 735 | return 0; |
738 | 736 | ||
739 | err_iounmap: | ||
740 | iounmap(dev->base); | ||
741 | err_release_clk: | 737 | err_release_clk: |
742 | clk_disable(dev->clk); | 738 | clk_disable(dev->clk); |
743 | clk_put(dev->clk); | 739 | clk_put(dev->clk); |
744 | err_free_mem: | ||
745 | kfree(dev); | ||
746 | err_release_region: | ||
747 | release_mem_region(mem->start, resource_size(mem)); | ||
748 | |||
749 | return ret; | 740 | return ret; |
750 | } | 741 | } |
751 | 742 | ||
752 | static int davinci_i2s_remove(struct platform_device *pdev) | 743 | static int davinci_i2s_remove(struct platform_device *pdev) |
753 | { | 744 | { |
754 | struct davinci_mcbsp_dev *dev = dev_get_drvdata(&pdev->dev); | 745 | struct davinci_mcbsp_dev *dev = dev_get_drvdata(&pdev->dev); |
755 | struct resource *mem; | ||
756 | 746 | ||
757 | snd_soc_unregister_dai(&pdev->dev); | 747 | snd_soc_unregister_dai(&pdev->dev); |
758 | clk_disable(dev->clk); | 748 | clk_disable(dev->clk); |
759 | clk_put(dev->clk); | 749 | clk_put(dev->clk); |
760 | dev->clk = NULL; | 750 | dev->clk = NULL; |
761 | kfree(dev); | ||
762 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
763 | release_mem_region(mem->start, resource_size(mem)); | ||
764 | 751 | ||
765 | return 0; | 752 | return 0; |
766 | } | 753 | } |