Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Johannes Berg and committed by
Jaroslav Kysela
d595ee7e 73e85fe8

+26 -46
+26 -46
sound/aoa/soundbus/i2sbus/i2sbus-pcm.c
··· 812 812 module_put(THIS_MODULE); 813 813 } 814 814 815 - /* FIXME: this function needs an error handling strategy with labels */ 816 815 int 817 816 i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card, 818 817 struct codec_info *ci, void *data) ··· 879 880 if (!cii->sdev) { 880 881 printk(KERN_DEBUG 881 882 "i2sbus: failed to get soundbus dev reference\n"); 882 - kfree(cii); 883 - return -ENODEV; 883 + err = -ENODEV; 884 + goto out_free_cii; 884 885 } 885 886 886 887 if (!try_module_get(THIS_MODULE)) { 887 888 printk(KERN_DEBUG "i2sbus: failed to get module reference!\n"); 888 - soundbus_dev_put(dev); 889 - kfree(cii); 890 - return -EBUSY; 889 + err = -EBUSY; 890 + goto out_put_sdev; 891 891 } 892 892 893 893 if (!try_module_get(ci->owner)) { 894 894 printk(KERN_DEBUG 895 895 "i2sbus: failed to get module reference to codec owner!\n"); 896 - module_put(THIS_MODULE); 897 - soundbus_dev_put(dev); 898 - kfree(cii); 899 - return -EBUSY; 896 + err = -EBUSY; 897 + goto out_put_this_module; 900 898 } 901 899 902 900 if (!dev->pcm) { ··· 901 905 &dev->pcm); 902 906 if (err) { 903 907 printk(KERN_DEBUG "i2sbus: failed to create pcm\n"); 904 - kfree(cii); 905 - module_put(ci->owner); 906 - soundbus_dev_put(dev); 907 - module_put(THIS_MODULE); 908 - return err; 908 + goto out_put_ci_module; 909 909 } 910 910 dev->pcm->dev = &dev->ofdev.dev; 911 911 } ··· 915 923 /* eh? */ 916 924 printk(KERN_ERR 917 925 "Can't attach same bus to different cards!\n"); 918 - module_put(ci->owner); 919 - kfree(cii); 920 - soundbus_dev_put(dev); 921 - module_put(THIS_MODULE); 922 - return -EINVAL; 926 + err = -EINVAL; 927 + goto out_put_ci_module; 923 928 } 924 - if ((err = 925 - snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 1))) { 926 - module_put(ci->owner); 927 - kfree(cii); 928 - soundbus_dev_put(dev); 929 - module_put(THIS_MODULE); 930 - return err; 931 - } 929 + err = snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 1); 930 + if (err) 931 + goto out_put_ci_module; 932 932 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 933 933 &i2sbus_playback_ops); 934 934 i2sdev->out.created = 1; ··· 930 946 if (dev->pcm->card != card) { 931 947 printk(KERN_ERR 932 948 "Can't attach same bus to different cards!\n"); 933 - module_put(ci->owner); 934 - kfree(cii); 935 - soundbus_dev_put(dev); 936 - module_put(THIS_MODULE); 937 - return -EINVAL; 949 + goto out_put_ci_module; 938 950 } 939 - if ((err = 940 - snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 1))) { 941 - module_put(ci->owner); 942 - kfree(cii); 943 - soundbus_dev_put(dev); 944 - module_put(THIS_MODULE); 945 - return err; 946 - } 951 + err = snd_pcm_new_stream(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 1); 952 + if (err) 953 + goto out_put_ci_module; 947 954 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 948 955 &i2sbus_record_ops); 949 956 i2sdev->in.created = 1; ··· 949 974 err = snd_device_register(card, dev->pcm); 950 975 if (err) { 951 976 printk(KERN_ERR "i2sbus: error registering new pcm\n"); 952 - module_put(ci->owner); 953 - kfree(cii); 954 - soundbus_dev_put(dev); 955 - module_put(THIS_MODULE); 956 - return err; 977 + goto out_put_ci_module; 957 978 } 958 979 /* no errors any more, so let's add this to our list */ 959 980 list_add(&cii->list, &dev->codec_list); ··· 964 993 64 * 1024, 64 * 1024); 965 994 966 995 return 0; 996 + out_put_ci_module: 997 + module_put(ci->owner); 998 + out_put_this_module: 999 + module_put(THIS_MODULE); 1000 + out_put_sdev: 1001 + soundbus_dev_put(dev); 1002 + out_free_cii: 1003 + kfree(cii); 1004 + return err; 967 1005 } 968 1006 969 1007 void i2sbus_detach_codec(struct soundbus_dev *dev, void *data)