[ALSA] unregister platform device again if probe was unsuccessful
[linux-3.10.git] / sound / drivers / dummy.c
index 186117571745ead8a87a5b4270c2bd81d8e2dd9d..ffeafaf2eccae64956ac2bfd8034257fbb10b92c 100644 (file)
@@ -92,11 +92,27 @@ static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
 #define USE_RATE_MAX           48000
 #endif
 
+#if 0 /* CA0106 */
+#define USE_FORMATS            SNDRV_PCM_FMTBIT_S16_LE
+#define USE_CHANNELS_MIN       2
+#define USE_CHANNELS_MAX       2
+#define USE_RATE               (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000) 
+#define USE_RATE_MIN           48000 
+#define USE_RATE_MAX           192000
+#define MAX_BUFFER_SIZE                ((65536-64)*8)
+#define MAX_PERIOD_SIZE                (65536-64)
+#define USE_PERIODS_MIN                2
+#define USE_PERIODS_MAX                8
+#endif
+
 
 /* defaults */
 #ifndef MAX_BUFFER_SIZE
 #define MAX_BUFFER_SIZE                (64*1024)
 #endif
+#ifndef MAX_PERIOD_SIZE
+#define MAX_PERIOD_SIZE                MAX_BUFFER_SIZE
+#endif
 #ifndef USE_FORMATS
 #define USE_FORMATS            (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
 #endif
@@ -144,6 +160,8 @@ MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
 //module_param_array(midi_devs, int, NULL, 0444);
 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
 
+static struct platform_device *devices[SNDRV_CARDS];
+
 #define MIXER_ADDR_MASTER      0
 #define MIXER_ADDR_LINE                1
 #define MIXER_ADDR_MIC         2
@@ -285,7 +303,7 @@ static struct snd_pcm_hardware snd_card_dummy_capture =
        .channels_max =         USE_CHANNELS_MAX,
        .buffer_bytes_max =     MAX_BUFFER_SIZE,
        .period_bytes_min =     64,
-       .period_bytes_max =     MAX_BUFFER_SIZE,
+       .period_bytes_max =     MAX_PERIOD_SIZE,
        .periods_min =          USE_PERIODS_MIN,
        .periods_max =          USE_PERIODS_MAX,
        .fifo_size =            0,
@@ -634,6 +652,15 @@ static struct platform_driver snd_dummy_driver = {
        },
 };
 
+static void __init_or_module snd_dummy_unregister_all(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(devices); ++i)
+               platform_device_unregister(devices[i]);
+       platform_driver_unregister(&snd_dummy_driver);
+}
+
 static int __init alsa_card_dummy_init(void)
 {
        int i, cards, err;
@@ -642,33 +669,34 @@ static int __init alsa_card_dummy_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_DUMMY_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 "Dummy soundcard not found or device busy\n");
 #endif
-               err = -ENODEV;
-               goto errout;
+               snd_dummy_unregister_all();
+               return -ENODEV;
        }
        return 0;
-
- errout:
-       platform_driver_unregister(&snd_dummy_driver);
-       return err;
 }
 
 static void __exit alsa_card_dummy_exit(void)
 {
-       platform_driver_unregister(&snd_dummy_driver);
+       snd_dummy_unregister_all();
 }
 
 module_init(alsa_card_dummy_init)