Commit cd0ff7ef authored by Julia Lawall's avatar Julia Lawall Committed by Mark Brown

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: default avatarJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 96d31e2b
...@@ -661,18 +661,18 @@ static int davinci_i2s_probe(struct platform_device *pdev) ...@@ -661,18 +661,18 @@ static int davinci_i2s_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
ioarea = request_mem_region(mem->start, resource_size(mem), ioarea = devm_request_mem_region(&pdev->dev, mem->start,
pdev->name); resource_size(mem),
pdev->name);
if (!ioarea) { if (!ioarea) {
dev_err(&pdev->dev, "McBSP region already claimed\n"); dev_err(&pdev->dev, "McBSP region already claimed\n");
return -EBUSY; return -EBUSY;
} }
dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL); dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcbsp_dev),
if (!dev) { GFP_KERNEL);
ret = -ENOMEM; if (!dev)
goto err_release_region; return -ENOMEM;
}
if (pdata) { if (pdata) {
dev->enable_channel_combine = pdata->enable_channel_combine; dev->enable_channel_combine = pdata->enable_channel_combine;
dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size = dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size =
...@@ -691,13 +691,11 @@ static int davinci_i2s_probe(struct platform_device *pdev) ...@@ -691,13 +691,11 @@ static int davinci_i2s_probe(struct platform_device *pdev)
dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].ram_chan_q = ram_chan_q; dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].ram_chan_q = ram_chan_q;
dev->clk = clk_get(&pdev->dev, NULL); dev->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(dev->clk)) { if (IS_ERR(dev->clk))
ret = -ENODEV; return -ENODEV;
goto err_free_mem;
}
clk_enable(dev->clk); clk_enable(dev->clk);
dev->base = ioremap(mem->start, resource_size(mem)); dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
if (!dev->base) { if (!dev->base) {
dev_err(&pdev->dev, "ioremap failed\n"); dev_err(&pdev->dev, "ioremap failed\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -715,7 +713,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) ...@@ -715,7 +713,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
if (!res) { if (!res) {
dev_err(&pdev->dev, "no DMA resource\n"); dev_err(&pdev->dev, "no DMA resource\n");
ret = -ENXIO; ret = -ENXIO;
goto err_iounmap; goto err_release_clk;
} }
dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start; dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start;
...@@ -723,7 +721,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) ...@@ -723,7 +721,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
if (!res) { if (!res) {
dev_err(&pdev->dev, "no DMA resource\n"); dev_err(&pdev->dev, "no DMA resource\n");
ret = -ENXIO; ret = -ENXIO;
goto err_iounmap; goto err_release_clk;
} }
dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start;
dev->dev = &pdev->dev; dev->dev = &pdev->dev;
...@@ -732,35 +730,24 @@ static int davinci_i2s_probe(struct platform_device *pdev) ...@@ -732,35 +730,24 @@ static int davinci_i2s_probe(struct platform_device *pdev)
ret = snd_soc_register_dai(&pdev->dev, &davinci_i2s_dai); ret = snd_soc_register_dai(&pdev->dev, &davinci_i2s_dai);
if (ret != 0) if (ret != 0)
goto err_iounmap; goto err_release_clk;
return 0; return 0;
err_iounmap:
iounmap(dev->base);
err_release_clk: err_release_clk:
clk_disable(dev->clk); clk_disable(dev->clk);
clk_put(dev->clk); clk_put(dev->clk);
err_free_mem:
kfree(dev);
err_release_region:
release_mem_region(mem->start, resource_size(mem));
return ret; return ret;
} }
static int davinci_i2s_remove(struct platform_device *pdev) static int davinci_i2s_remove(struct platform_device *pdev)
{ {
struct davinci_mcbsp_dev *dev = dev_get_drvdata(&pdev->dev); struct davinci_mcbsp_dev *dev = dev_get_drvdata(&pdev->dev);
struct resource *mem;
snd_soc_unregister_dai(&pdev->dev); snd_soc_unregister_dai(&pdev->dev);
clk_disable(dev->clk); clk_disable(dev->clk);
clk_put(dev->clk); clk_put(dev->clk);
dev->clk = NULL; dev->clk = NULL;
kfree(dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, resource_size(mem));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment