[alsa-devel] [PATCH 0/8] ASoC: fix resource leak in error paths
This serial of patches fix resource leak in error paths.
Axel Lin (8): ASoC: efika-audio-fabric: fix resource leak in efika_fabric_init error path ASoC: pcm030-audio-fabric: fix resource leak in pcm030_fabric_init error path ASoC: snd-soc-afeb9260: remove unneeded platform_device_del in error path ASoC: sam9g20_wm8731: fix resource leak in at91sam9g20ek_init error path ASoC: smdk_wm9713: fix resource leak in smdk_init error path ASoC: simone: fix resource leak in simone_init error path ASoC: imx-ssi: fix resource leak ASoC: phycore-ac97: fix resource leak
sound/soc/atmel/sam9g20_wm8731.c | 5 ++++- sound/soc/atmel/snd-soc-afeb9260.c | 1 - sound/soc/ep93xx/simone.c | 18 ++++++++++-------- sound/soc/fsl/efika-audio-fabric.c | 1 + sound/soc/fsl/pcm030-audio-fabric.c | 1 + sound/soc/imx/imx-ssi.c | 15 +++++++++++---- sound/soc/imx/phycore-ac97.c | 28 +++++++++++++++++++++------- sound/soc/samsung/smdk_wm9713.c | 17 ++++++++++------- 8 files changed, 58 insertions(+), 28 deletions(-)
Add missing platform_device_put() if platform_device_add() failed.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/fsl/efika-audio-fabric.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/sound/soc/fsl/efika-audio-fabric.c b/sound/soc/fsl/efika-audio-fabric.c index 53251e6..108b5d8 100644 --- a/sound/soc/fsl/efika-audio-fabric.c +++ b/sound/soc/fsl/efika-audio-fabric.c @@ -76,6 +76,7 @@ static __init int efika_fabric_init(void) rc = platform_device_add(pdev); if (rc) { pr_err("efika_fabric_init: platform_device_add() failed\n"); + platform_device_put(pdev); return -ENODEV; } return 0;
Add missing platform_device_put() if platform_device_add() failed.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/fsl/pcm030-audio-fabric.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c index 25f27ec..ba4d85e 100644 --- a/sound/soc/fsl/pcm030-audio-fabric.c +++ b/sound/soc/fsl/pcm030-audio-fabric.c @@ -76,6 +76,7 @@ static __init int pcm030_fabric_init(void) rc = platform_device_add(pdev); if (rc) { pr_err("pcm030_fabric_init: platform_device_add() failed\n"); + platform_device_put(pdev); return -ENODEV; } return 0;
From f3b1f9a02fe390b2f12b9097a1d4d9de55618b34 Mon Sep 17 00:00:00 2001
From: Axel Lin axel.lin@gmail.com Date: Thu, 25 Nov 2010 10:44:59 +0800 Subject: [PATCH 3/8] ASoC: snd-soc-afeb9260: remove unneeded platform_device_del in error path
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/atmel/snd-soc-afeb9260.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/sound/soc/atmel/snd-soc-afeb9260.c b/sound/soc/atmel/snd-soc-afeb9260.c index 1202f5e..da2208e 100644 --- a/sound/soc/atmel/snd-soc-afeb9260.c +++ b/sound/soc/atmel/snd-soc-afeb9260.c @@ -167,7 +167,6 @@ static int __init afeb9260_soc_init(void)
return 0; err1: - platform_device_del(afeb9260_snd_device); platform_device_put(afeb9260_snd_device); return err; }
Fix the error path to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/atmel/sam9g20_wm8731.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c index 1c9de19..af3c730 100644 --- a/sound/soc/atmel/sam9g20_wm8731.c +++ b/sound/soc/atmel/sam9g20_wm8731.c @@ -240,6 +240,7 @@ static int __init at91sam9g20ek_init(void) if (!at91sam9g20ek_snd_device) { printk(KERN_ERR "ASoC: Platform device allocation failed\n"); ret = -ENOMEM; + goto err_mclk; }
platform_set_drvdata(at91sam9g20ek_snd_device, @@ -248,11 +249,13 @@ static int __init at91sam9g20ek_init(void) ret = platform_device_add(at91sam9g20ek_snd_device); if (ret) { printk(KERN_ERR "ASoC: Platform device allocation failed\n"); - platform_device_put(at91sam9g20ek_snd_device); + goto err_device_add; }
return ret;
+err_device_add: + platform_device_put(at91sam9g20ek_snd_device); err_mclk: clk_put(mclk); mclk = NULL;
Fix the error path to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/samsung/smdk_wm9713.c | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/sound/soc/samsung/smdk_wm9713.c b/sound/soc/samsung/smdk_wm9713.c index 7ce2430..238cb3a 100644 --- a/sound/soc/samsung/smdk_wm9713.c +++ b/sound/soc/samsung/smdk_wm9713.c @@ -70,24 +70,27 @@ static int __init smdk_init(void)
ret = platform_device_add(smdk_snd_wm9713_device); if (ret) - goto err; + goto err1;
smdk_snd_ac97_device = platform_device_alloc("soc-audio", -1); if (!smdk_snd_ac97_device) { ret = -ENOMEM; - goto err; + goto err2; }
platform_set_drvdata(smdk_snd_ac97_device, &smdk);
ret = platform_device_add(smdk_snd_ac97_device); - if (ret) { - platform_device_put(smdk_snd_ac97_device); - goto err; - } + if (ret) + goto err3;
return 0; -err: + +err3: + platform_device_put(smdk_snd_ac97_device); +err2: + platform_device_del(smdk_snd_wm9713_device); +err1: platform_device_put(smdk_snd_wm9713_device); return ret; }
Fix the error path to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/ep93xx/simone.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/sound/soc/ep93xx/simone.c b/sound/soc/ep93xx/simone.c index 4b0d199..2868179 100644 --- a/sound/soc/ep93xx/simone.c +++ b/sound/soc/ep93xx/simone.c @@ -54,24 +54,26 @@ static int __init simone_init(void)
ret = platform_device_add(simone_snd_ac97_device); if (ret) - goto fail; + goto fail1;
simone_snd_device = platform_device_alloc("soc-audio", -1); if (!simone_snd_device) { ret = -ENOMEM; - goto fail; + goto fail2; }
platform_set_drvdata(simone_snd_device, &snd_soc_simone); ret = platform_device_add(simone_snd_device); - if (ret) { - platform_device_put(simone_snd_device); - goto fail; - } + if (ret) + goto fail3;
- return ret; + return 0;
-fail: +fail3: + platform_device_put(simone_snd_device); +fail2: + platform_device_del(simone_snd_ac97_device); +fail1: platform_device_put(simone_snd_ac97_device); return ret; }
On Thu, Nov 25, 2010 at 03:12:30PM +0800, Axel Lin wrote:
Fix the error path to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com
Acked-by: Mika Westerberg mika.westerberg@iki.fi
Thanks for catching this.
sound/soc/ep93xx/simone.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/sound/soc/ep93xx/simone.c b/sound/soc/ep93xx/simone.c index 4b0d199..2868179 100644 --- a/sound/soc/ep93xx/simone.c +++ b/sound/soc/ep93xx/simone.c @@ -54,24 +54,26 @@ static int __init simone_init(void)
ret = platform_device_add(simone_snd_ac97_device); if (ret)
goto fail;
goto fail1;
simone_snd_device = platform_device_alloc("soc-audio", -1); if (!simone_snd_device) { ret = -ENOMEM;
goto fail;
goto fail2;
}
platform_set_drvdata(simone_snd_device, &snd_soc_simone); ret = platform_device_add(simone_snd_device);
- if (ret) {
platform_device_put(simone_snd_device);
goto fail;
- }
- if (ret)
goto fail3;
- return ret;
- return 0;
-fail: +fail3:
- platform_device_put(simone_snd_device);
+fail2:
- platform_device_del(simone_snd_ac97_device);
+fail1: platform_device_put(simone_snd_ac97_device); return ret; } -- 1.7.2
Fix imx_ssi_probe() error path and imx_ssi_remove() to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/imx/imx-ssi.c | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/imx/imx-ssi.c index ad21f81..30894ea 100644 --- a/sound/soc/imx/imx-ssi.c +++ b/sound/soc/imx/imx-ssi.c @@ -679,8 +679,11 @@ static int imx_ssi_probe(struct platform_device *pdev) }
ssi->soc_platform_pdev_fiq = platform_device_alloc("imx-fiq-pcm-audio", pdev->id); - if (!ssi->soc_platform_pdev_fiq) + if (!ssi->soc_platform_pdev_fiq) { + ret = -ENOMEM; goto failed_pdev_fiq_alloc; + } + platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi); ret = platform_device_add(ssi->soc_platform_pdev_fiq); if (ret) { @@ -689,8 +692,11 @@ static int imx_ssi_probe(struct platform_device *pdev) }
ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", pdev->id); - if (!ssi->soc_platform_pdev) + if (!ssi->soc_platform_pdev) { + ret = -ENOMEM; goto failed_pdev_alloc; + } + platform_set_drvdata(ssi->soc_platform_pdev, ssi); ret = platform_device_add(ssi->soc_platform_pdev); if (ret) { @@ -703,6 +709,7 @@ static int imx_ssi_probe(struct platform_device *pdev) failed_pdev_add: platform_device_put(ssi->soc_platform_pdev); failed_pdev_alloc: + platform_device_del(ssi->soc_platform_pdev_fiq); failed_pdev_fiq_add: platform_device_put(ssi->soc_platform_pdev_fiq); failed_pdev_fiq_alloc: @@ -726,8 +733,8 @@ static int __devexit imx_ssi_remove(struct platform_device *pdev) struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct imx_ssi *ssi = platform_get_drvdata(pdev);
- platform_device_del(ssi->soc_platform_pdev); - platform_device_put(ssi->soc_platform_pdev); + platform_device_unregister(ssi->soc_platform_pdev); + platform_device_unregister(ssi->soc_platform_pdev_fiq);
snd_soc_unregister_dai(&pdev->dev);
On Thu, Nov 25, 2010 at 03:13:09PM +0800, Axel Lin wrote:
Fix imx_ssi_probe() error path and imx_ssi_remove() to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com
Acked-by: Sascha Hauer s.hauer@pengutronix.de
sound/soc/imx/imx-ssi.c | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/sound/soc/imx/imx-ssi.c b/sound/soc/imx/imx-ssi.c index ad21f81..30894ea 100644 --- a/sound/soc/imx/imx-ssi.c +++ b/sound/soc/imx/imx-ssi.c @@ -679,8 +679,11 @@ static int imx_ssi_probe(struct platform_device *pdev) }
ssi->soc_platform_pdev_fiq = platform_device_alloc("imx-fiq-pcm-audio", pdev->id);
- if (!ssi->soc_platform_pdev_fiq)
- if (!ssi->soc_platform_pdev_fiq) {
goto failed_pdev_fiq_alloc;ret = -ENOMEM;
- }
- platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi); ret = platform_device_add(ssi->soc_platform_pdev_fiq); if (ret) {
@@ -689,8 +692,11 @@ static int imx_ssi_probe(struct platform_device *pdev) }
ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", pdev->id);
- if (!ssi->soc_platform_pdev)
- if (!ssi->soc_platform_pdev) {
goto failed_pdev_alloc;ret = -ENOMEM;
- }
- platform_set_drvdata(ssi->soc_platform_pdev, ssi); ret = platform_device_add(ssi->soc_platform_pdev); if (ret) {
@@ -703,6 +709,7 @@ static int imx_ssi_probe(struct platform_device *pdev) failed_pdev_add: platform_device_put(ssi->soc_platform_pdev); failed_pdev_alloc:
- platform_device_del(ssi->soc_platform_pdev_fiq);
failed_pdev_fiq_add: platform_device_put(ssi->soc_platform_pdev_fiq); failed_pdev_fiq_alloc: @@ -726,8 +733,8 @@ static int __devexit imx_ssi_remove(struct platform_device *pdev) struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct imx_ssi *ssi = platform_get_drvdata(pdev);
- platform_device_del(ssi->soc_platform_pdev);
- platform_device_put(ssi->soc_platform_pdev);
platform_device_unregister(ssi->soc_platform_pdev);
platform_device_unregister(ssi->soc_platform_pdev_fiq);
snd_soc_unregister_dai(&pdev->dev);
-- 1.7.2
Fix imx_phycore_init() error path and imx_phycore_exit() to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com --- sound/soc/imx/phycore-ac97.c | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/imx/phycore-ac97.c index db157f7..a7deb5c 100644 --- a/sound/soc/imx/phycore-ac97.c +++ b/sound/soc/imx/phycore-ac97.c @@ -42,6 +42,7 @@ static struct snd_soc_card imx_phycore = { .num_links = ARRAY_SIZE(imx_phycore_dai_ac97), };
+static struct platform_device *imx_phycore_snd_ac97_device; static struct platform_device *imx_phycore_snd_device;
static int __init imx_phycore_init(void) @@ -52,29 +53,42 @@ static int __init imx_phycore_init(void) /* return happy. We might run on a totally different machine */ return 0;
- imx_phycore_snd_device = platform_device_alloc("soc-audio", -1); - if (!imx_phycore_snd_device) + imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1); + if (!imx_phycore_snd_ac97_device) return -ENOMEM;
- platform_set_drvdata(imx_phycore_snd_device, &imx_phycore); - ret = platform_device_add(imx_phycore_snd_device); + platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore); + ret = platform_device_add(imx_phycore_snd_ac97_device); + if (ret) + goto fail1;
imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1); - if (!imx_phycore_snd_device) - return -ENOMEM; + if (!imx_phycore_snd_device) { + ret = -ENOMEM; + goto fail2; + } ret = platform_device_add(imx_phycore_snd_device);
if (ret) { printk(KERN_ERR "ASoC: Platform device allocation failed\n"); - platform_device_put(imx_phycore_snd_device); + goto fail3; }
+ return 0; + +fail3: + platform_device_put(imx_phycore_snd_device); +fail2: + platform_device_del(imx_phycore_snd_ac97_device); +fail1: + platform_device_put(imx_phycore_snd_ac97_device); return ret; }
static void __exit imx_phycore_exit(void) { platform_device_unregister(imx_phycore_snd_device); + platform_device_unregister(imx_phycore_snd_ac97_device); }
late_initcall(imx_phycore_init);
On Thu, Nov 25, 2010 at 03:14:03PM +0800, Axel Lin wrote:
Fix imx_phycore_init() error path and imx_phycore_exit() to properly free allocated resources.
Signed-off-by: Axel Lin axel.lin@gmail.com
Acked-by: Sascha Hauer s.hauer@pengutronix.de
sound/soc/imx/phycore-ac97.c | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/imx/phycore-ac97.c index db157f7..a7deb5c 100644 --- a/sound/soc/imx/phycore-ac97.c +++ b/sound/soc/imx/phycore-ac97.c @@ -42,6 +42,7 @@ static struct snd_soc_card imx_phycore = { .num_links = ARRAY_SIZE(imx_phycore_dai_ac97), };
+static struct platform_device *imx_phycore_snd_ac97_device; static struct platform_device *imx_phycore_snd_device;
static int __init imx_phycore_init(void) @@ -52,29 +53,42 @@ static int __init imx_phycore_init(void) /* return happy. We might run on a totally different machine */ return 0;
- imx_phycore_snd_device = platform_device_alloc("soc-audio", -1);
- if (!imx_phycore_snd_device)
- imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1);
- if (!imx_phycore_snd_ac97_device) return -ENOMEM;
- platform_set_drvdata(imx_phycore_snd_device, &imx_phycore);
- ret = platform_device_add(imx_phycore_snd_device);
platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore);
ret = platform_device_add(imx_phycore_snd_ac97_device);
if (ret)
goto fail1;
imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1);
- if (!imx_phycore_snd_device)
return -ENOMEM;
if (!imx_phycore_snd_device) {
ret = -ENOMEM;
goto fail2;
} ret = platform_device_add(imx_phycore_snd_device);
if (ret) { printk(KERN_ERR "ASoC: Platform device allocation failed\n");
platform_device_put(imx_phycore_snd_device);
goto fail3;
}
return 0;
+fail3:
- platform_device_put(imx_phycore_snd_device);
+fail2:
- platform_device_del(imx_phycore_snd_ac97_device);
+fail1:
- platform_device_put(imx_phycore_snd_ac97_device); return ret;
}
static void __exit imx_phycore_exit(void) { platform_device_unregister(imx_phycore_snd_device);
- platform_device_unregister(imx_phycore_snd_ac97_device);
}
late_initcall(imx_phycore_init);
1.7.2
On Thu, 2010-11-25 at 15:06 +0800, Axel Lin wrote:
This serial of patches fix resource leak in error paths.
Axel Lin (8): ASoC: efika-audio-fabric: fix resource leak in efika_fabric_init error path ASoC: pcm030-audio-fabric: fix resource leak in pcm030_fabric_init error path ASoC: snd-soc-afeb9260: remove unneeded platform_device_del in error path ASoC: sam9g20_wm8731: fix resource leak in at91sam9g20ek_init error path ASoC: smdk_wm9713: fix resource leak in smdk_init error path ASoC: simone: fix resource leak in simone_init error path ASoC: imx-ssi: fix resource leak ASoC: phycore-ac97: fix resource leak
sound/soc/atmel/sam9g20_wm8731.c | 5 ++++- sound/soc/atmel/snd-soc-afeb9260.c | 1 - sound/soc/ep93xx/simone.c | 18 ++++++++++-------- sound/soc/fsl/efika-audio-fabric.c | 1 + sound/soc/fsl/pcm030-audio-fabric.c | 1 + sound/soc/imx/imx-ssi.c | 15 +++++++++++---- sound/soc/imx/phycore-ac97.c | 28 +++++++++++++++++++++------- sound/soc/samsung/smdk_wm9713.c | 17 ++++++++++------- 8 files changed, 58 insertions(+), 28 deletions(-)
All
Acked-by: Liam Girdwood lrg@slimlogic.co.uk
participants (5)
-
Axel Lin
-
Liam Girdwood
-
Mark Brown
-
Mika Westerberg
-
Sascha Hauer