ALSA: jack: Unregister input device at disconnection
[sfrench/cifs-2.6.git] / sound / core / jack.c
index b35fe7345c203c557d2baa5d0cbb778afac2dfb9..8658578eb584997ec867a864a4e31a124519f828 100644 (file)
@@ -34,12 +34,12 @@ static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
        SW_LINEIN_INSERT,
 };
 
        SW_LINEIN_INSERT,
 };
 
-static int snd_jack_dev_free(struct snd_device *device)
+static int snd_jack_dev_disconnect(struct snd_device *device)
 {
        struct snd_jack *jack = device->device_data;
 
 {
        struct snd_jack *jack = device->device_data;
 
-       if (jack->private_free)
-               jack->private_free(jack);
+       if (!jack->input_dev)
+               return 0;
 
        /* If the input device is registered with the input subsystem
         * then we need to use a different deallocator. */
 
        /* If the input device is registered with the input subsystem
         * then we need to use a different deallocator. */
@@ -47,6 +47,18 @@ static int snd_jack_dev_free(struct snd_device *device)
                input_unregister_device(jack->input_dev);
        else
                input_free_device(jack->input_dev);
                input_unregister_device(jack->input_dev);
        else
                input_free_device(jack->input_dev);
+       jack->input_dev = NULL;
+       return 0;
+}
+
+static int snd_jack_dev_free(struct snd_device *device)
+{
+       struct snd_jack *jack = device->device_data;
+
+       if (jack->private_free)
+               jack->private_free(jack);
+
+       snd_jack_dev_disconnect(device);
 
        kfree(jack->id);
        kfree(jack);
 
        kfree(jack->id);
        kfree(jack);
@@ -110,6 +122,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
        static struct snd_device_ops ops = {
                .dev_free = snd_jack_dev_free,
                .dev_register = snd_jack_dev_register,
        static struct snd_device_ops ops = {
                .dev_free = snd_jack_dev_free,
                .dev_register = snd_jack_dev_register,
+               .dev_disconnect = snd_jack_dev_disconnect,
        };
 
        jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
        };
 
        jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);