]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - sound/core/sound.c
Check fops_get() return value
[linux-2.6.git] / sound / core / sound.c
index 00cca4d6e56226e454484b0fc660102c55f1bdc4..7872a02f6ca998602b588dc6ba4d7741c3e08c1b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/time.h>
 #include <linux/device.h>
 #include <linux/moduleparam.h>
@@ -33,8 +34,6 @@
 #include <linux/kmod.h>
 #include <linux/mutex.h>
 
-#define SNDRV_OS_MINORS 256
-
 static int major = CONFIG_SND_MAJOR;
 int snd_major;
 EXPORT_SYMBOL(snd_major);
@@ -60,19 +59,17 @@ EXPORT_SYMBOL(snd_ecards_limit);
 static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
 static DEFINE_MUTEX(sound_mutex);
 
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
 
 /**
  * snd_request_card - try to load the card module
  * @card: the card number
  *
  * Tries to load the module "snd-card-X" for the given card number
- * via KMOD.  Returns immediately if already loaded.
+ * via request_module.  Returns immediately if already loaded.
  */
 void snd_request_card(int card)
 {
-       if (! current->fs->root)
-               return;
        if (snd_card_locked(card))
                return;
        if (card < 0 || card >= cards_limit)
@@ -86,8 +83,6 @@ static void snd_request_other(int minor)
 {
        char *str;
 
-       if (! current->fs->root)
-               return;
        switch (minor) {
        case SNDRV_MINOR_SEQUENCER:     str = "snd-seq";        break;
        case SNDRV_MINOR_TIMER:         str = "snd-timer";      break;
@@ -96,7 +91,7 @@ static void snd_request_other(int minor)
        request_module(str);
 }
 
-#endif                         /* request_module support */
+#endif /* modular kernel */
 
 /**
  * snd_lookup_minor_data - get user data of a registered device
@@ -125,7 +120,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
 
 EXPORT_SYMBOL(snd_lookup_minor_data);
 
-static int snd_open(struct inode *inode, struct file *file)
+static int __snd_open(struct inode *inode, struct file *file)
 {
        unsigned int minor = iminor(inode);
        struct snd_minor *mptr = NULL;
@@ -136,7 +131,7 @@ static int snd_open(struct inode *inode, struct file *file)
                return -ENODEV;
        mptr = snd_minors[minor];
        if (mptr == NULL) {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
                int dev = SNDRV_MINOR_DEVICE(minor);
                if (dev == SNDRV_MINOR_CONTROL) {
                        /* /dev/aloadC? */
@@ -157,6 +152,10 @@ static int snd_open(struct inode *inode, struct file *file)
        }
        old_fops = file->f_op;
        file->f_op = fops_get(mptr->f_ops);
+       if (file->f_op == NULL) {
+               file->f_op = old_fops;
+               return -ENODEV;
+       }
        if (file->f_op->open)
                err = file->f_op->open(inode, file);
        if (err) {
@@ -167,6 +166,18 @@ static int snd_open(struct inode *inode, struct file *file)
        return err;
 }
 
+
+/* BKL pushdown: nasty #ifdef avoidance wrapper */
+static int snd_open(struct inode *inode, struct file *file)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __snd_open(inode, file);
+       unlock_kernel();
+       return ret;
+}
+
 static const struct file_operations snd_fops =
 {
        .owner =        THIS_MODULE,
@@ -199,20 +210,23 @@ static int snd_kernel_minor(int type, struct snd_card *card, int dev)
                minor = type;
                break;
        case SNDRV_DEVICE_TYPE_CONTROL:
-               snd_assert(card != NULL, return -EINVAL);
+               if (snd_BUG_ON(!card))
+                       return -EINVAL;
                minor = SNDRV_MINOR(card->number, type);
                break;
        case SNDRV_DEVICE_TYPE_HWDEP:
        case SNDRV_DEVICE_TYPE_RAWMIDI:
        case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
        case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
-               snd_assert(card != NULL, return -EINVAL);
+               if (snd_BUG_ON(!card))
+                       return -EINVAL;
                minor = SNDRV_MINOR(card->number, type + dev);
                break;
        default:
                return -EINVAL;
        }
-       snd_assert(minor >= 0 && minor < SNDRV_OS_MINORS, return -EINVAL);
+       if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
+               return -EINVAL;
        return minor;
 }
 #endif
@@ -240,7 +254,8 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
        int minor;
        struct snd_minor *preg;
 
-       snd_assert(name, return -EINVAL);
+       if (snd_BUG_ON(!name))
+               return -EINVAL;
        preg = kmalloc(sizeof *preg, GFP_KERNEL);
        if (preg == NULL)
                return -ENOMEM;
@@ -264,7 +279,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
        }
        snd_minors[minor] = preg;
        preg->dev = device_create(sound_class, device, MKDEV(major, minor),
-                                 "%s", name);
+                                 private_data, "%s", name);
        if (IS_ERR(preg->dev)) {
                snd_minors[minor] = NULL;
                mutex_unlock(&sound_mutex);
@@ -273,9 +288,6 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
                return minor;
        }
 
-       if (preg->dev)
-               dev_set_drvdata(preg->dev, private_data);
-
        mutex_unlock(&sound_mutex);
        return 0;
 }