]> err.no Git - linux-2.6/blobdiff - drivers/sbus/char/vfc_dev.c
sbus-rtc: BKL pushdown
[linux-2.6] / drivers / sbus / char / vfc_dev.c
index 55b2b31bd7abbf0d2dbcde64af303c952b442821..1f6cb8ae2784cddaf76aa949033381b271126037 100644 (file)
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
-#include <linux/sched.h>
 #include <linux/fs.h>
-#include <linux/smp_lock.h>
 #include <linux/delay.h>
 #include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 
 #include <asm/openprom.h>
 #include <asm/oplib.h>
@@ -44,7 +44,7 @@
 #include "vfc.h"
 #include <asm/vfc_ioctls.h>
 
-static struct file_operations vfc_fops;
+static const struct file_operations vfc_fops;
 struct vfc_dev **vfc_dev_lst;
 static char vfcstr[]="vfc";
 static unsigned char saa9051_init_array[VFC_SAA9051_NR] = {
@@ -56,12 +56,12 @@ static unsigned char saa9051_init_array[VFC_SAA9051_NR] = {
 
 void vfc_lock_device(struct vfc_dev *dev)
 {
-       down(&dev->device_lock_sem);
+       mutex_lock(&dev->device_lock_mtx);
 }
 
 void vfc_unlock_device(struct vfc_dev *dev)
 {
-       up(&dev->device_lock_sem);
+       mutex_unlock(&dev->device_lock_mtx);
 }
 
 
@@ -135,7 +135,7 @@ int init_vfc_hw(struct vfc_dev *dev)
 int init_vfc_devstruct(struct vfc_dev *dev, int instance) 
 {
        dev->instance=instance;
-       init_MUTEX(&dev->device_lock_sem);
+       mutex_init(&dev->device_lock_mtx);
        dev->control_reg=0;
        dev->busy=0;
        return 0;
@@ -179,14 +179,17 @@ static int vfc_open(struct inode *inode, struct file *file)
 {
        struct vfc_dev *dev;
 
+       lock_kernel();
        spin_lock(&vfc_dev_lock);
        dev = vfc_get_dev_ptr(iminor(inode));
        if (dev == NULL) {
                spin_unlock(&vfc_dev_lock);
+               unlock_kernel();
                return -ENODEV;
        }
        if (dev->busy) {
                spin_unlock(&vfc_dev_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -203,6 +206,7 @@ static int vfc_open(struct inode *inode, struct file *file)
        vfc_captstat_reset(dev);
        
        vfc_unlock_device(dev);
+       unlock_kernel();
        return 0;
 }
 
@@ -250,6 +254,7 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, void __user *argp)
                                        buffer,inout.len);
 
                if (copy_to_user(argp,&inout,sizeof(inout))) {
+                       vfc_unlock_device(dev);
                        kfree(buffer);
                        return -EFAULT;
                }
@@ -260,11 +265,10 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, void __user *argp)
                if (copy_from_user(&inout, argp, sizeof(inout)))
                        return -EFAULT;
 
-               buffer = kmalloc(inout.len, GFP_KERNEL);
+               buffer = kzalloc(inout.len, GFP_KERNEL);
                if (buffer == NULL)
                        return -ENOMEM;
 
-               memset(buffer,0,inout.len);
                vfc_lock_device(dev);
                inout.ret=
                        vfc_i2c_recvbuf(dev,inout.addr & 0xff
@@ -610,7 +614,7 @@ static int vfc_mmap(struct file *file, struct vm_area_struct *vma)
        unsigned int map_size, ret, map_offset;
        struct vfc_dev *dev;
        
-       dev = vfc_get_dev_ptr(iminor(file->f_dentry->d_inode));
+       dev = vfc_get_dev_ptr(iminor(file->f_path.dentry->d_inode));
        if(dev == NULL)
                return -ENODEV;
 
@@ -633,7 +637,7 @@ static int vfc_mmap(struct file *file, struct vm_area_struct *vma)
 }
 
 
-static struct file_operations vfc_fops = {
+static const struct file_operations vfc_fops = {
        .owner =        THIS_MODULE,
        .llseek =       no_llseek,
        .ioctl =        vfc_ioctl,
@@ -659,12 +663,9 @@ static int vfc_probe(void)
        if (!cards)
                return -ENODEV;
 
-       vfc_dev_lst = (struct vfc_dev **)kmalloc(sizeof(struct vfc_dev *) *
-                                                (cards+1),
-                                                GFP_KERNEL);
+       vfc_dev_lst = kcalloc(cards + 1, sizeof(struct vfc_dev*), GFP_KERNEL);
        if (vfc_dev_lst == NULL)
                return -ENOMEM;
-       memset(vfc_dev_lst, 0, sizeof(struct vfc_dev *) * (cards + 1));
        vfc_dev_lst[cards] = NULL;
 
        ret = register_chrdev(VFC_MAJOR, vfcstr, &vfc_fops);