aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-09-30 05:40:37 -0400
committerTakashi Iwai <tiwai@suse.de>2008-09-30 06:47:12 -0400
commite3145dfb7b4262fa55907006b75da799de8c1be3 (patch)
tree5260088839385b751953cb0ad47cef9633f9ad23 /sound
parent9778e9a0eafe796c2affcd1fa1fa8a3765e026e6 (diff)
ALSA: ASoC: Fix cs4270 error path
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> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/cs4270.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index d68650de39bc..0bbd94501d7e 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -681,7 +681,7 @@ static int cs4270_probe(struct platform_device *pdev)
681 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 681 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
682 if (ret < 0) { 682 if (ret < 0) {
683 printk(KERN_ERR "cs4270: failed to create PCMs\n"); 683 printk(KERN_ERR "cs4270: failed to create PCMs\n");
684 return ret; 684 goto error_free_codec;
685 } 685 }
686 686
687#ifdef USE_I2C 687#ifdef USE_I2C
@@ -690,8 +690,7 @@ static int cs4270_probe(struct platform_device *pdev)
690 ret = i2c_add_driver(&cs4270_i2c_driver); 690 ret = i2c_add_driver(&cs4270_i2c_driver);
691 if (ret) { 691 if (ret) {
692 printk(KERN_ERR "cs4270: failed to attach driver"); 692 printk(KERN_ERR "cs4270: failed to attach driver");
693 snd_soc_free_pcms(socdev); 693 goto error_free_pcms;
694 return ret;
695 } 694 }
696 695
697 /* Did we find a CS4270 on the I2C bus? */ 696 /* Did we find a CS4270 on the I2C bus? */
@@ -713,10 +712,23 @@ static int cs4270_probe(struct platform_device *pdev)
713 ret = snd_soc_register_card(socdev); 712 ret = snd_soc_register_card(socdev);
714 if (ret < 0) { 713 if (ret < 0) {
715 printk(KERN_ERR "cs4270: failed to register card\n"); 714 printk(KERN_ERR "cs4270: failed to register card\n");
716 snd_soc_free_pcms(socdev); 715 goto error_del_driver;
717 return ret;
718 } 716 }
719 717
718 return 0;
719
720error_del_driver:
721#ifdef USE_I2C
722 i2c_del_driver(&cs4270_i2c_driver);
723
724error_free_pcms:
725#endif
726 snd_soc_free_pcms(socdev);
727
728error_free_codec:
729 kfree(socdev->codec);
730 socdev->codec = NULL;
731
720 return ret; 732 return ret;
721} 733}
722 734
@@ -727,8 +739,7 @@ static int cs4270_remove(struct platform_device *pdev)
727 snd_soc_free_pcms(socdev); 739 snd_soc_free_pcms(socdev);
728 740
729#ifdef USE_I2C 741#ifdef USE_I2C
730 if (socdev->codec->control_data) 742 i2c_del_driver(&cs4270_i2c_driver);
731 i2c_del_driver(&cs4270_i2c_driver);
732#endif 743#endif
733 744
734 kfree(socdev->codec); 745 kfree(socdev->codec);