]> Pileus Git - ~andy/linux/blobdiff - sound/isa/ad1848/ad1848.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-tc
[~andy/linux] / sound / isa / ad1848 / ad1848.c
index 1019e9fdff539e6d4c5b353be6525ed8a1262b54..99908e44124da32593b6fa85ea87eafeb4cc1c6b 100644 (file)
@@ -62,6 +62,8 @@ MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver.");
 module_param_array(thinkpad, bool, NULL, 0444);
 MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
 
+static struct platform_device *devices[SNDRV_CARDS];
+
 
 static int __init snd_ad1848_probe(struct platform_device *pdev)
 {
@@ -167,6 +169,15 @@ static struct platform_driver snd_ad1848_driver = {
        },
 };
 
+static void __init_or_module snd_ad1848_unregister_all(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(devices); ++i)
+               platform_device_unregister(devices[i]);
+       platform_driver_unregister(&snd_ad1848_driver);
+}
+
 static int __init alsa_card_ad1848_init(void)
 {
        int i, cards, err;
@@ -176,33 +187,34 @@ static int __init alsa_card_ad1848_init(void)
                return err;
 
        cards = 0;
-       for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
+       for (i = 0; i < SNDRV_CARDS; i++) {
                struct platform_device *device;
+               if (! enable[i])
+                       continue;
                device = platform_device_register_simple(SND_AD1848_DRIVER,
                                                         i, NULL, 0);
-               if (IS_ERR(device)) {
-                       err = PTR_ERR(device);
-                       goto errout;
+               if (IS_ERR(device))
+                       continue;
+               if (!platform_get_drvdata(device)) {
+                       platform_device_unregister(device);
+                       continue;
                }
+               devices[i] = device;
                cards++;
        }
        if (!cards) {
 #ifdef MODULE
                printk(KERN_ERR "AD1848 soundcard not found or device busy\n");
 #endif
-               err = -ENODEV;
-               goto errout;
+               snd_ad1848_unregister_all();
+               return -ENODEV;
        }
        return 0;
-
- errout:
-       platform_driver_unregister(&snd_ad1848_driver);
-       return err;
 }
 
 static void __exit alsa_card_ad1848_exit(void)
 {
-       platform_driver_unregister(&snd_ad1848_driver);
+       snd_ad1848_unregister_all();
 }
 
 module_init(alsa_card_ad1848_init)