Merge branch 'fix/misc' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[safe/jmp/linux-2.6] / sound / core / sound.c
index 09a9495..7872a02 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);
@@ -121,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;
@@ -153,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) {
@@ -163,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,
@@ -195,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
@@ -236,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;
@@ -259,9 +278,8 @@ int snd_register_device_for_dev(int type, struct snd_card *card, int dev,
                return minor;
        }
        snd_minors[minor] = preg;
-       preg->dev = device_create_drvdata(sound_class, device,
-                                         MKDEV(major, minor),
-                                         private_data, "%s", name);
+       preg->dev = device_create(sound_class, device, MKDEV(major, minor),
+                                 private_data, "%s", name);
        if (IS_ERR(preg->dev)) {
                snd_minors[minor] = NULL;
                mutex_unlock(&sound_mutex);