All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: Fix cs4270 error path
@ 2008-08-31 12:42 Jean Delvare
  2008-09-22 12:29 ` Jean Delvare
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Jean Delvare @ 2008-08-31 12:42 UTC (permalink / raw)
  To: Timur Tabi; +Cc: alsa-devel

The error path in cs4270_probe/cs4270_remove is pretty broken:
* If cs4270_probe fails, codec is leaked.
* If snd_soc_register_card fails, cs4270_i2c_driver stays registered.
* If I2C support is enabled but no I2C device is found, i2c_del_driver
  is never called (neither in cs4270_probe nor in cs4270_remove.)

Fix the first 2 problems by implementing a clean error path in
cs4270_probe and jumping to its labels as needed. Fix the 3rd problem
by removing the condition to call i2c_del_driver in cs4270_remove.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
---
Timur, can you please review and test this patch? I do not have the
hardware so I couldn't test it myself.

 sound/soc/codecs/cs4270.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

--- linux-2.6.27-rc5.orig/sound/soc/codecs/cs4270.c	2008-08-31 13:59:17.000000000 +0200
+++ linux-2.6.27-rc5/sound/soc/codecs/cs4270.c	2008-08-31 14:23:34.000000000 +0200
@@ -727,7 +727,7 @@ static int cs4270_probe(struct platform_
 	ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
 	if (ret < 0) {
 		printk(KERN_ERR "cs4270: failed to create PCMs\n");
-		return ret;
+		goto error_free_codec;
 	}
 
 #ifdef USE_I2C
@@ -736,8 +736,7 @@ static int cs4270_probe(struct platform_
 	ret = i2c_add_driver(&cs4270_i2c_driver);
 	if (ret) {
 		printk(KERN_ERR "cs4270: failed to attach driver");
-		snd_soc_free_pcms(socdev);
-		return ret;
+		goto error_free_pcms;
 	}
 
 	/* Did we find a CS4270 on the I2C bus? */
@@ -759,10 +758,23 @@ static int cs4270_probe(struct platform_
 	ret = snd_soc_register_card(socdev);
 	if (ret < 0) {
 		printk(KERN_ERR "cs4270: failed to register card\n");
-		snd_soc_free_pcms(socdev);
-		return ret;
+		goto error_del_driver;
 	}
 
+	return 0;
+
+error_del_driver:
+#ifdef USE_I2C
+	i2c_del_driver(&cs4270_i2c_driver);
+
+error_free_pcms:
+#endif
+	snd_soc_free_pcms(socdev);
+
+error_free_codec:
+	kfree(socdev->codec);
+	socdev->codec = NULL;
+
 	return ret;
 }
 
@@ -773,8 +785,7 @@ static int cs4270_remove(struct platform
 	snd_soc_free_pcms(socdev);
 
 #ifdef USE_I2C
-	if (socdev->codec->control_data)
-		i2c_del_driver(&cs4270_i2c_driver);
+	i2c_del_driver(&cs4270_i2c_driver);
 #endif
 
 	kfree(socdev->codec);


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] ASoC: Fix cs4270 error path
@ 2008-09-30  9:40 Jean Delvare
  0 siblings, 0 replies; 15+ messages in thread
From: Jean Delvare @ 2008-09-30  9:40 UTC (permalink / raw)
  To: alsa-devel, Takashi Iwai; +Cc: Timur Tabi

The error path in cs4270_probe/cs4270_remove is pretty broken:
* If cs4270_probe fails, codec is leaked.
* If snd_soc_register_card fails, cs4270_i2c_driver stays registered.
* If I2C support is enabled but no I2C device is found, i2c_del_driver
  is never called (neither in cs4270_probe nor in cs4270_remove.

Fix all 3 problems by implementing a clean error path in cs4270_probe
and jumping to its labels as needed.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Timur Tabi <timur@freescale.com>
---
 sound/soc/codecs/cs4270.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

--- linux-2.6.27-rc8.orig/sound/soc/codecs/cs4270.c	2008-09-30 11:11:22.000000000 +0200
+++ linux-2.6.27-rc8/sound/soc/codecs/cs4270.c	2008-09-30 11:33:03.000000000 +0200
@@ -681,7 +681,7 @@ static int cs4270_probe(struct platform_
 	ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
 	if (ret < 0) {
 		printk(KERN_ERR "cs4270: failed to create PCMs\n");
-		return ret;
+		goto error_free_codec;
 	}
 
 #ifdef USE_I2C
@@ -690,8 +690,7 @@ static int cs4270_probe(struct platform_
 	ret = i2c_add_driver(&cs4270_i2c_driver);
 	if (ret) {
 		printk(KERN_ERR "cs4270: failed to attach driver");
-		snd_soc_free_pcms(socdev);
-		return ret;
+		goto error_free_pcms;
 	}
 
 	/* Did we find a CS4270 on the I2C bus? */
@@ -713,10 +712,23 @@ static int cs4270_probe(struct platform_
 	ret = snd_soc_register_card(socdev);
 	if (ret < 0) {
 		printk(KERN_ERR "cs4270: failed to register card\n");
-		snd_soc_free_pcms(socdev);
-		return ret;
+		goto error_del_driver;
 	}
 
+	return 0;
+
+error_del_driver:
+#ifdef USE_I2C
+	i2c_del_driver(&cs4270_i2c_driver);
+
+error_free_pcms:
+#endif
+	snd_soc_free_pcms(socdev);
+
+error_free_codec:
+	kfree(socdev->codec);
+	socdev->codec = NULL;
+
 	return ret;
 }
 
@@ -727,8 +739,7 @@ static int cs4270_remove(struct platform
 	snd_soc_free_pcms(socdev);
 
 #ifdef USE_I2C
-	if (socdev->codec->control_data)
-		i2c_del_driver(&cs4270_i2c_driver);
+	i2c_del_driver(&cs4270_i2c_driver);
 #endif
 
 	kfree(socdev->codec);


-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-09-30 15:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-31 12:42 [PATCH] ASoC: Fix cs4270 error path Jean Delvare
2008-09-22 12:29 ` Jean Delvare
2008-09-22 20:35 ` Timur Tabi
2008-09-27 16:09   ` Jean Delvare
2008-09-29 13:42 ` Timur Tabi
2008-09-29 13:48   ` Takashi Iwai
2008-09-30  8:31     ` Jean Delvare
2008-09-30  8:53       ` Takashi Iwai
2008-09-30  9:38         ` Jean Delvare
2008-09-30 11:08           ` Takashi Iwai
2008-09-30 14:25         ` Timur Tabi
2008-09-30 14:49           ` Takashi Iwai
2008-09-30 14:56             ` Timur Tabi
2008-09-30 15:03               ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2008-09-30  9:40 Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.