[alsa-devel] [PATCH 01/14] ASoC: Fix an error path in neo1973_wm8753

Mark Brown broonie at opensource.wolfsonmicro.com
Fri Sep 5 16:35:09 CEST 2008


From: Jean Delvare <khali at linux-fr.org>

The error handling in neo1973_init is incorrect:

* If platform_device_add fails, we go on with the rest of the
  initialization instead of bailing out. Things will break when the
  module is removed (platform_device_unregister called on a device
  that wasn't registered.)

* If i2c_add_driver fails, we return an error so the module will not
  load, but we don't unregister neo1973_snd_device, so we are leaking
  resources.

Add the missing error handling.

Signed-off-by: Jean Delvare <khali at linux-fr.org>
Cc: Tim Niemeyer <reddog at mastersword.de>
Cc: Graeme Gregory <graeme at openmoko.org>
Cc: Mark Brown <broonie at opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie at opensource.wolfsonmicro.com>
---
 sound/soc/s3c24xx/neo1973_wm8753.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 8089f8e..3aa441f 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -717,12 +717,16 @@ static int __init neo1973_init(void)
 	neo1973_snd_devdata.dev = &neo1973_snd_device->dev;
 	ret = platform_device_add(neo1973_snd_device);
 
-	if (ret)
+	if (ret) {
 		platform_device_put(neo1973_snd_device);
+		return ret;
+	}
 
 	ret = i2c_add_driver(&lm4857_i2c_driver);
-	if (ret != 0)
+	if (ret != 0) {
 		printk(KERN_ERR "can't add i2c driver");
+		platform_device_unregister(neo1973_snd_device);
+	}
 
 	return ret;
 }
-- 
1.5.6.5



More information about the Alsa-devel mailing list