Commit 226d0f22 authored by Julia Lawall's avatar Julia Lawall Committed by Mark Brown

ASoC: keep pointer to resource so it can be freed

Add a new variable for storing resources accessed subsequent to the one
accessed using request_mem_region, so the one accessed using
request_mem_region can be released if needed.

The resource variable names are also changed to be more descriptive.

This code is also missing some calls to iounmap.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

if (E == NULL)
{
  ... when != if (E == NULL || ...) S1 else S2
      when != E = E1
*E->f
  ... when any
  return ...;
}
else S3
// </smpl>
Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 33cb92cf
...@@ -226,7 +226,7 @@ static struct snd_soc_dai_driver au1xac97c_dai_driver = { ...@@ -226,7 +226,7 @@ static struct snd_soc_dai_driver au1xac97c_dai_driver = {
static int __devinit au1xac97c_drvprobe(struct platform_device *pdev) static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
{ {
int ret; int ret;
struct resource *r; struct resource *iores, *dmares;
struct au1xpsc_audio_data *ctx; struct au1xpsc_audio_data *ctx;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
...@@ -235,29 +235,30 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev) ...@@ -235,29 +235,30 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
mutex_init(&ctx->lock); mutex_init(&ctx->lock);
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) { if (!iores) {
ret = -ENODEV; ret = -ENODEV;
goto out0; goto out0;
} }
ret = -EBUSY; ret = -EBUSY;
if (!request_mem_region(r->start, resource_size(r), pdev->name)) if (!request_mem_region(iores->start, resource_size(iores),
pdev->name))
goto out0; goto out0;
ctx->mmio = ioremap_nocache(r->start, resource_size(r)); ctx->mmio = ioremap_nocache(iores->start, resource_size(iores));
if (!ctx->mmio) if (!ctx->mmio)
goto out1; goto out1;
r = platform_get_resource(pdev, IORESOURCE_DMA, 0); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!r) if (!dmares)
goto out1; goto out2;
ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
r = platform_get_resource(pdev, IORESOURCE_DMA, 1); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
if (!r) if (!dmares)
goto out1; goto out2;
ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
/* switch it on */ /* switch it on */
WR(ctx, AC97_ENABLE, EN_D | EN_CE); WR(ctx, AC97_ENABLE, EN_D | EN_CE);
...@@ -270,13 +271,15 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev) ...@@ -270,13 +271,15 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver); ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver);
if (ret) if (ret)
goto out1; goto out2;
ac97c_workdata = ctx; ac97c_workdata = ctx;
return 0; return 0;
out2:
iounmap(ctx->mmio);
out1: out1:
release_mem_region(r->start, resource_size(r)); release_mem_region(iores->start, resource_size(iores));
out0: out0:
kfree(ctx); kfree(ctx);
return ret; return ret;
......
...@@ -228,47 +228,50 @@ static struct snd_soc_dai_driver au1xi2s_dai_driver = { ...@@ -228,47 +228,50 @@ static struct snd_soc_dai_driver au1xi2s_dai_driver = {
static int __devinit au1xi2s_drvprobe(struct platform_device *pdev) static int __devinit au1xi2s_drvprobe(struct platform_device *pdev)
{ {
int ret; int ret;
struct resource *r; struct resource *iores, *dmares;
struct au1xpsc_audio_data *ctx; struct au1xpsc_audio_data *ctx;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) { if (!iores) {
ret = -ENODEV; ret = -ENODEV;
goto out0; goto out0;
} }
ret = -EBUSY; ret = -EBUSY;
if (!request_mem_region(r->start, resource_size(r), pdev->name)) if (!request_mem_region(iores->start, resource_size(iores),
pdev->name))
goto out0; goto out0;
ctx->mmio = ioremap_nocache(r->start, resource_size(r)); ctx->mmio = ioremap_nocache(iores->start, resource_size(iores));
if (!ctx->mmio) if (!ctx->mmio)
goto out1; goto out1;
r = platform_get_resource(pdev, IORESOURCE_DMA, 0); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!r) if (!dmares)
goto out1; goto out2;
ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
r = platform_get_resource(pdev, IORESOURCE_DMA, 1); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
if (!r) if (!dmares)
goto out1; goto out2;
ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
platform_set_drvdata(pdev, ctx); platform_set_drvdata(pdev, ctx);
ret = snd_soc_register_dai(&pdev->dev, &au1xi2s_dai_driver); ret = snd_soc_register_dai(&pdev->dev, &au1xi2s_dai_driver);
if (ret) if (ret)
goto out1; goto out2;
return 0; return 0;
out2:
iounmap(ctx->mmio);
out1: out1:
release_mem_region(r->start, resource_size(r)); release_mem_region(iores->start, resource_size(iores));
out0: out0:
kfree(ctx); kfree(ctx);
return ret; return ret;
......
...@@ -364,7 +364,7 @@ static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = { ...@@ -364,7 +364,7 @@ static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = {
static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev) static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
{ {
int ret; int ret;
struct resource *r; struct resource *iores, *dmares;
unsigned long sel; unsigned long sel;
struct au1xpsc_audio_data *wd; struct au1xpsc_audio_data *wd;
...@@ -374,29 +374,30 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev) ...@@ -374,29 +374,30 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
mutex_init(&wd->lock); mutex_init(&wd->lock);
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) { if (!iores) {
ret = -ENODEV; ret = -ENODEV;
goto out0; goto out0;
} }
ret = -EBUSY; ret = -EBUSY;
if (!request_mem_region(r->start, resource_size(r), pdev->name)) if (!request_mem_region(iores->start, resource_size(iores),
pdev->name))
goto out0; goto out0;
wd->mmio = ioremap(r->start, resource_size(r)); wd->mmio = ioremap(iores->start, resource_size(iores));
if (!wd->mmio) if (!wd->mmio)
goto out1; goto out1;
r = platform_get_resource(pdev, IORESOURCE_DMA, 0); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!r) if (!dmares)
goto out2; goto out2;
wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
r = platform_get_resource(pdev, IORESOURCE_DMA, 1); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
if (!r) if (!dmares)
goto out2; goto out2;
wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
/* configuration: max dma trigger threshold, enable ac97 */ /* configuration: max dma trigger threshold, enable ac97 */
wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 | wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 |
...@@ -428,7 +429,7 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev) ...@@ -428,7 +429,7 @@ static int __devinit au1xpsc_ac97_drvprobe(struct platform_device *pdev)
out2: out2:
iounmap(wd->mmio); iounmap(wd->mmio);
out1: out1:
release_mem_region(r->start, resource_size(r)); release_mem_region(iores->start, resource_size(iores));
out0: out0:
kfree(wd); kfree(wd);
return ret; return ret;
......
...@@ -290,7 +290,7 @@ static const struct snd_soc_dai_driver au1xpsc_i2s_dai_template = { ...@@ -290,7 +290,7 @@ static const struct snd_soc_dai_driver au1xpsc_i2s_dai_template = {
static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev) static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
{ {
struct resource *r; struct resource *iores, *dmares;
unsigned long sel; unsigned long sel;
int ret; int ret;
struct au1xpsc_audio_data *wd; struct au1xpsc_audio_data *wd;
...@@ -299,29 +299,30 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev) ...@@ -299,29 +299,30 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
if (!wd) if (!wd)
return -ENOMEM; return -ENOMEM;
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) { if (!iores) {
ret = -ENODEV; ret = -ENODEV;
goto out0; goto out0;
} }
ret = -EBUSY; ret = -EBUSY;
if (!request_mem_region(r->start, resource_size(r), pdev->name)) if (!request_mem_region(iores->start, resource_size(iores),
pdev->name))
goto out0; goto out0;
wd->mmio = ioremap(r->start, resource_size(r)); wd->mmio = ioremap(iores->start, resource_size(iores));
if (!wd->mmio) if (!wd->mmio)
goto out1; goto out1;
r = platform_get_resource(pdev, IORESOURCE_DMA, 0); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!r) if (!dmares)
goto out2; goto out2;
wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
r = platform_get_resource(pdev, IORESOURCE_DMA, 1); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
if (!r) if (!dmares)
goto out2; goto out2;
wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
/* preserve PSC clock source set up by platform (dev.platform_data /* preserve PSC clock source set up by platform (dev.platform_data
* is already occupied by soc layer) * is already occupied by soc layer)
...@@ -355,7 +356,7 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev) ...@@ -355,7 +356,7 @@ static int __devinit au1xpsc_i2s_drvprobe(struct platform_device *pdev)
out2: out2:
iounmap(wd->mmio); iounmap(wd->mmio);
out1: out1:
release_mem_region(r->start, resource_size(r)); release_mem_region(iores->start, resource_size(iores));
out0: out0:
kfree(wd); kfree(wd);
return ret; return ret;
......
...@@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id) ...@@ -617,7 +617,7 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
static int mxs_saif_probe(struct platform_device *pdev) static int mxs_saif_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *iores, *dmares;
struct mxs_saif *saif; struct mxs_saif *saif;
struct mxs_saif_platform_data *pdata; struct mxs_saif_platform_data *pdata;
int ret = 0; int ret = 0;
...@@ -655,35 +655,36 @@ static int mxs_saif_probe(struct platform_device *pdev) ...@@ -655,35 +655,36 @@ static int mxs_saif_probe(struct platform_device *pdev)
goto failed_clk; goto failed_clk;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!iores) {
ret = -ENODEV; ret = -ENODEV;
dev_err(&pdev->dev, "failed to get io resource: %d\n", dev_err(&pdev->dev, "failed to get io resource: %d\n",
ret); ret);
goto failed_get_resource; goto failed_get_resource;
} }
if (!request_mem_region(res->start, resource_size(res), "mxs-saif")) { if (!request_mem_region(iores->start, resource_size(iores),
"mxs-saif")) {
dev_err(&pdev->dev, "request_mem_region failed\n"); dev_err(&pdev->dev, "request_mem_region failed\n");
ret = -EBUSY; ret = -EBUSY;
goto failed_get_resource; goto failed_get_resource;
} }
saif->base = ioremap(res->start, resource_size(res)); saif->base = ioremap(iores->start, resource_size(iores));
if (!saif->base) { if (!saif->base) {
dev_err(&pdev->dev, "ioremap failed\n"); dev_err(&pdev->dev, "ioremap failed\n");
ret = -ENODEV; ret = -ENODEV;
goto failed_ioremap; goto failed_ioremap;
} }
res = platform_get_resource(pdev, IORESOURCE_DMA, 0); dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!res) { if (!dmares) {
ret = -ENODEV; ret = -ENODEV;
dev_err(&pdev->dev, "failed to get dma resource: %d\n", dev_err(&pdev->dev, "failed to get dma resource: %d\n",
ret); ret);
goto failed_ioremap; goto failed_ioremap;
} }
saif->dma_param.chan_num = res->start; saif->dma_param.chan_num = dmares->start;
saif->irq = platform_get_irq(pdev, 0); saif->irq = platform_get_irq(pdev, 0);
if (saif->irq < 0) { if (saif->irq < 0) {
...@@ -742,7 +743,7 @@ static int mxs_saif_probe(struct platform_device *pdev) ...@@ -742,7 +743,7 @@ static int mxs_saif_probe(struct platform_device *pdev)
failed_get_irq1: failed_get_irq1:
iounmap(saif->base); iounmap(saif->base);
failed_ioremap: failed_ioremap:
release_mem_region(res->start, resource_size(res)); release_mem_region(iores->start, resource_size(iores));
failed_get_resource: failed_get_resource:
clk_put(saif->clk); clk_put(saif->clk);
failed_clk: failed_clk:
......
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