[PATCH] selinux: Clear selinux_enabled flag upon runtime disable.
[firefly-linux-kernel-4.4.55.git] / sound / core / sound_oss.c
index afbfd8df129826c79c3eb41a37e29e5cbb7c2129..9055c6de95875d4b199dce59b0db0b1fe5737ed6 100644 (file)
 #include <sound/minors.h>
 #include <sound/info.h>
 #include <linux/sound.h>
+#include <linux/mutex.h>
 
 #define SNDRV_OSS_MINORS 128
 
 static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS];
+static DEFINE_MUTEX(sound_oss_mutex);
 
-static DECLARE_MUTEX(sound_oss_mutex);
+void *snd_lookup_oss_minor_data(unsigned int minor, int type)
+{
+       struct snd_minor *mreg;
+       void *private_data;
+
+       if (minor >= ARRAY_SIZE(snd_oss_minors))
+               return NULL;
+       mutex_lock(&sound_oss_mutex);
+       mreg = snd_oss_minors[minor];
+       if (mreg && mreg->type == type)
+               private_data = mreg->private_data;
+       else
+               private_data = NULL;
+       mutex_unlock(&sound_oss_mutex);
+       return private_data;
+}
 
 static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
 {
@@ -78,7 +95,8 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
 }
 
 int snd_register_oss_device(int type, struct snd_card *card, int dev,
-                           struct file_operations *f_ops, const char *name)
+                           const struct file_operations *f_ops, void *private_data,
+                           const char *name)
 {
        int minor = snd_oss_kernel_minor(type, card, dev);
        int minor_unit;
@@ -88,6 +106,8 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,
        int register1 = -1, register2 = -1;
        struct device *carddev = NULL;
 
+       if (card && card->number >= 8)
+               return 0; /* ignore silently */
        if (minor < 0)
                return minor;
        preg = kmalloc(sizeof(struct snd_minor), GFP_KERNEL);
@@ -97,7 +117,8 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,
        preg->card = card ? card->number : -1;
        preg->device = dev;
        preg->f_ops = f_ops;
-       down(&sound_oss_mutex);
+       preg->private_data = private_data;
+       mutex_lock(&sound_oss_mutex);
        snd_oss_minors[minor] = preg;
        minor_unit = SNDRV_MINOR_OSS_DEVICE(minor);
        switch (minor_unit) {
@@ -121,8 +142,9 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,
                                                          carddev);
                if (register2 != track2)
                        goto __end;
+               snd_oss_minors[track2] = preg;
        }
-       up(&sound_oss_mutex);
+       mutex_unlock(&sound_oss_mutex);
        return 0;
 
       __end:
@@ -131,7 +153,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,
        if (register1 >= 0)
                unregister_sound_special(register1);
        snd_oss_minors[minor] = NULL;
-       up(&sound_oss_mutex);
+       mutex_unlock(&sound_oss_mutex);
        kfree(preg);
        return -EBUSY;
 }
@@ -143,12 +165,14 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)
        int track2 = -1;
        struct snd_minor *mptr;
 
+       if (card && card->number >= 8)
+               return 0;
        if (minor < 0)
                return minor;
-       down(&sound_oss_mutex);
+       mutex_lock(&sound_oss_mutex);
        mptr = snd_oss_minors[minor];
        if (mptr == NULL) {
-               up(&sound_oss_mutex);
+               mutex_unlock(&sound_oss_mutex);
                return -ENOENT;
        }
        unregister_sound_special(minor);
@@ -163,10 +187,12 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)
                track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
                break;
        }
-       if (track2 >= 0)
+       if (track2 >= 0) {
                unregister_sound_special(track2);
+               snd_oss_minors[track2] = NULL;
+       }
        snd_oss_minors[minor] = NULL;
-       up(&sound_oss_mutex);
+       mutex_unlock(&sound_oss_mutex);
        kfree(mptr);
        return 0;
 }
@@ -204,7 +230,7 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,
        int minor;
        struct snd_minor *mptr;
 
-       down(&sound_oss_mutex);
+       mutex_lock(&sound_oss_mutex);
        for (minor = 0; minor < SNDRV_OSS_MINORS; ++minor) {
                if (!(mptr = snd_oss_minors[minor]))
                        continue;
@@ -216,14 +242,12 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,
                        snd_iprintf(buffer, "%3i:       : %s\n", minor,
                                    snd_oss_device_type_name(mptr->type));
        }
-       up(&sound_oss_mutex);
+       mutex_unlock(&sound_oss_mutex);
 }
 
-#endif /* CONFIG_PROC_FS */
 
 int __init snd_minor_info_oss_init(void)
 {
-#ifdef CONFIG_PROC_FS
        struct snd_info_entry *entry;
 
        entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root);
@@ -236,17 +260,15 @@ int __init snd_minor_info_oss_init(void)
                }
        }
        snd_minor_info_oss_entry = entry;
-#endif
        return 0;
 }
 
 int __exit snd_minor_info_oss_done(void)
 {
-#ifdef CONFIG_PROC_FS
        if (snd_minor_info_oss_entry)
                snd_info_unregister(snd_minor_info_oss_entry);
-#endif
        return 0;
 }
+#endif /* CONFIG_PROC_FS */
 
 #endif /* CONFIG_SND_OSSEMUL */