ASoC: ac97c.c: use devm_ functions
Julia Lawall [Thu, 29 Dec 2011 16:51:29 +0000 (17:51 +0100)]
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.

Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

sound/soc/au1x/ac97c.c

index 7771934..c5ac244 100644 (file)
@@ -229,35 +229,34 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
        struct resource *iores, *dmares;
        struct au1xpsc_audio_data *ctx;
 
-       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
        if (!ctx)
                return -ENOMEM;
 
        mutex_init(&ctx->lock);
 
        iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!iores) {
-               ret = -ENODEV;
-               goto out0;
-       }
+       if (!iores)
+               return -ENODEV;
 
-       ret = -EBUSY;
-       if (!request_mem_region(iores->start, resource_size(iores),
-                               pdev->name))
-               goto out0;
+       if (!devm_request_mem_region(&pdev->dev, iores->start,
+                                    resource_size(iores),
+                                    pdev->name))
+               return -EBUSY;
 
-       ctx->mmio = ioremap_nocache(iores->start, resource_size(iores));
+       ctx->mmio = devm_ioremap_nocache(&pdev->dev, iores->start,
+                                        resource_size(iores));
        if (!ctx->mmio)
-               goto out1;
+               return -EBUSY;
 
        dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
        if (!dmares)
-               goto out2;
+               return -EBUSY;
        ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
 
        dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
        if (!dmares)
-               goto out2;
+               return -EBUSY;
        ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
 
        /* switch it on */
@@ -271,33 +270,20 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
 
        ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver);
        if (ret)
-               goto out2;
+               return ret;
 
        ac97c_workdata = ctx;
        return 0;
-
-out2:
-       iounmap(ctx->mmio);
-out1:
-       release_mem_region(iores->start, resource_size(iores));
-out0:
-       kfree(ctx);
-       return ret;
 }
 
 static int __devexit au1xac97c_drvremove(struct platform_device *pdev)
 {
        struct au1xpsc_audio_data *ctx = platform_get_drvdata(pdev);
-       struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
        snd_soc_unregister_dai(&pdev->dev);
 
        WR(ctx, AC97_ENABLE, EN_D);     /* clock off, disable */
 
-       iounmap(ctx->mmio);
-       release_mem_region(r->start, resource_size(r));
-       kfree(ctx);
-
        ac97c_workdata = NULL;  /* MDEV */
 
        return 0;