aboutsummaryrefslogtreecommitdiffstats
path: root/sound/aoa/soundbus
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2006-10-05 09:08:23 -0400
committerJaroslav Kysela <perex@suse.cz>2007-02-09 03:00:09 -0500
commitd595ee7e0162ae66faa8c4c7d8c2069b40d64fed (patch)
tree91c1abaaee1b3498b031ea2142bd80456f20e702 /sound/aoa/soundbus
parent73e85fe8452b950b93cfb61377f749e9b15437fb (diff)
[ALSA] aoa: fix up i2sbus_attach_codec
This patch changes i2sbus_attach_codec to implement a proper error handling strategy using labels to jump to the right part. Since it has an elaborate set-up sequence it also needs that tear-down, which I had hard-coded inbetween all the checks. This increases readability and should reduce .text size as well. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/aoa/soundbus')
-rw-r--r--sound/aoa/soundbus/i2sbus/i2sbus-pcm.c72
1 files changed, 26 insertions, 46 deletions
diff --git a/sound/aoa/soundbus/i2sbus/i2sbus-pcm.c b/sound/aoa/soundbus/i2sbus/i2sbus-pcm.c
index 051bb9b200e..7c81db7e52c 100644
--- a/sound/aoa/soundbus/i2sbus/i2sbus-pcm.c
+++ b/sound/aoa/soundbus/i2sbus/i2sbus-pcm.c
@@ -812,7 +812,6 @@ static void i2sbus_private_free(struct snd_pcm *pcm)
812 module_put(THIS_MODULE); 812 module_put(THIS_MODULE);
813} 813}
814 814
815/* FIXME: this function needs an error handling strategy with labels */
816int 815int
817i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card, 816i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
818 struct codec_info *ci, void *data) 817 struct codec_info *ci, void *data)
@@ -880,24 +879,21 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
880 if (!cii->sdev) { 879 if (!cii->sdev) {
881 printk(KERN_DEBUG 880 printk(KERN_DEBUG
882 "i2sbus: failed to get soundbus dev reference\n"); 881 "i2sbus: failed to get soundbus dev reference\n");
883 kfree(cii); 882 err = -ENODEV;
884 return -ENODEV; 883 goto out_free_cii;
885 } 884 }
886 885
887 if (!try_module_get(THIS_MODULE)) { 886 if (!try_module_get(THIS_MODULE)) {
888 printk(KERN_DEBUG "i2sbus: failed to get module reference!\n"); 887 printk(KERN_DEBUG "i2sbus: failed to get module reference!\n");
889 soundbus_dev_put(dev); 888 err = -EBUSY;
890 kfree(cii); 889 goto out_put_sdev;
891 return -EBUSY;
892 } 890 }
893 891
894 if (!try_module_get(ci->owner)) { 892 if (!try_module_get(ci->owner)) {
895 printk(KERN_DEBUG 893 printk(KERN_DEBUG
896 "i2sbus: failed to get module reference to codec owner!\n"); 894 "i2sbus: failed to get module reference to codec owner!\n");
897 module_put(THIS_MODULE); 895 err = -EBUSY;
898 soundbus_dev_put(dev); 896 goto out_put_this_module;
899 kfree(cii);
900 return -EBUSY;
901 } 897 }
902 898
903 if (!dev->pcm) { 899 if (!dev->pcm) {
@@ -905,11 +901,7 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
905 &dev->pcm); 901 &dev->pcm);
906 if (err) { 902 if (err) {
907 printk(KERN_DEBUG "i2sbus: failed to create pcm\n"); 903 printk(KERN_DEBUG "i2sbus: failed to create pcm\n");
908 kfree(cii); 904 goto out_put_ci_module;
909 module_put(ci->owner);
910 soundbus_dev_put(dev);
911 module_put(THIS_MODULE);
912 return err;
913 } 905 }
914 dev->pcm->dev = &dev->ofdev.dev; 906 dev->pcm->dev = &dev->ofdev.dev;
915 } 907 }
@@ -923,20 +915,12 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
923 /* eh? */ 915 /* eh? */
924 printk(KERN_ERR 916 printk(KERN_ERR
925 "Can't attach same bus to different cards!\n"); 917 "Can't attach same bus to different cards!\n");
926 module_put(ci->owner); 918 err = -EINVAL;
927 kfree(cii); 919 goto out_put_ci_module;
928 soundbus_dev_put(dev);
929 module_put(THIS_MODULE);
930 return -EINVAL;
931 }
932 if ((err =
933 snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 1))) {
934 module_put(ci->owner);
935 kfree(cii);
936 soundbus_dev_put(dev);
937 module_put(THIS_MODULE);
938 return err;
939 } 920 }
921 err = snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 1);
922 if (err)
923 goto out_put_ci_module;
940 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 924 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
941 &i2sbus_playback_ops); 925 &i2sbus_playback_ops);
942 i2sdev->out.created = 1; 926 i2sdev->out.created = 1;
@@ -946,20 +930,11 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
946 if (dev->pcm->card != card) { 930 if (dev->pcm->card != card) {
947 printk(KERN_ERR 931 printk(KERN_ERR
948 "Can't attach same bus to different cards!\n"); 932 "Can't attach same bus to different cards!\n");
949 module_put(ci->owner); 933 goto out_put_ci_module;
950 kfree(cii);
951 soundbus_dev_put(dev);
952 module_put(THIS_MODULE);
953 return -EINVAL;
954 }
955 if ((err =
956 snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 1))) {
957 module_put(ci->owner);
958 kfree(cii);
959 soundbus_dev_put(dev);
960 module_put(THIS_MODULE);
961 return err;
962 } 934 }
935 err = snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 1);
936 if (err)
937 goto out_put_ci_module;
963 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 938 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE,
964 &i2sbus_record_ops); 939 &i2sbus_record_ops);
965 i2sdev->in.created = 1; 940 i2sdev->in.created = 1;
@@ -974,11 +949,7 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
974 err = snd_device_register(card, dev->pcm); 949 err = snd_device_register(card, dev->pcm);
975 if (err) { 950 if (err) {
976 printk(KERN_ERR "i2sbus: error registering new pcm\n"); 951 printk(KERN_ERR "i2sbus: error registering new pcm\n");
977 module_put(ci->owner); 952 goto out_put_ci_module;
978 kfree(cii);
979 soundbus_dev_put(dev);
980 module_put(THIS_MODULE);
981 return err;
982 } 953 }
983 /* no errors any more, so let's add this to our list */ 954 /* no errors any more, so let's add this to our list */
984 list_add(&cii->list, &dev->codec_list); 955 list_add(&cii->list, &dev->codec_list);
@@ -993,6 +964,15 @@ i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
993 64 * 1024, 64 * 1024); 964 64 * 1024, 64 * 1024);
994 965
995 return 0; 966 return 0;
967 out_put_ci_module:
968 module_put(ci->owner);
969 out_put_this_module:
970 module_put(THIS_MODULE);
971 out_put_sdev:
972 soundbus_dev_put(dev);
973 out_free_cii:
974 kfree(cii);
975 return err;
996} 976}
997 977
998void i2sbus_detach_codec(struct soundbus_dev *dev, void *data) 978void i2sbus_detach_codec(struct soundbus_dev *dev, void *data)