jsflash: BKL pushdown
[safe/jmp/linux-2.6] / drivers / sbus / char / jsflash.c
index c12c504..2bec9cc 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -185,7 +186,7 @@ static void jsfd_read(char *buf, unsigned long p, size_t togo) {
        }
 }
 
-static void jsfd_do_request(request_queue_t *q)
+static void jsfd_do_request(struct request_queue *q)
 {
        struct request *req;
 
@@ -249,11 +250,11 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)
 /*
  * OS SIMM Cannot be read in other size but a 32bits word.
  */
-static ssize_t jsf_read(struct file * file, char * buf, 
+static ssize_t jsf_read(struct file * file, char __user * buf, 
     size_t togo, loff_t *ppos)
 {
        unsigned long p = *ppos;
-       char *tmp = buf;
+       char __user *tmp = buf;
 
        union byte4 {
                char s[4];
@@ -305,7 +306,7 @@ static ssize_t jsf_read(struct file * file, char * buf,
        return tmp-buf;
 }
 
-static ssize_t jsf_write(struct file * file, const char * buf,
+static ssize_t jsf_write(struct file * file, const char __user * buf,
     size_t count, loff_t *ppos)
 {
        return -ENOSPC;
@@ -356,10 +357,10 @@ static int jsf_ioctl_erase(unsigned long arg)
  * Program a block of flash.
  * Very simple because we can do it byte by byte anyway.
  */
-static int jsf_ioctl_program(unsigned long arg)
+static int jsf_ioctl_program(void __user *arg)
 {
        struct jsflash_program_arg abuf;
-       char *uptr;
+       char __user *uptr;
        unsigned long p;
        unsigned int togo;
        union {
@@ -367,13 +368,13 @@ static int jsf_ioctl_program(unsigned long arg)
                char s[4];
        } b;
 
-       if (copy_from_user(&abuf, (char *)arg, JSFPRGSZ))
+       if (copy_from_user(&abuf, arg, JSFPRGSZ))
                return -EFAULT; 
        p = abuf.off;
        togo = abuf.size;
        if ((togo & 3) || (p & 3)) return -EINVAL;
 
-       uptr = (char *) (unsigned long) abuf.data;
+       uptr = (char __user *) (unsigned long) abuf.data;
        while (togo != 0) {
                togo -= 4;
                if (copy_from_user(&b.s[0], uptr, 4))
@@ -390,19 +391,20 @@ static int jsf_ioctl(struct inode *inode, struct file *f, unsigned int cmd,
     unsigned long arg)
 {
        int error = -ENOTTY;
+       void __user *argp = (void __user *)arg;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
        switch (cmd) {
        case JSFLASH_IDENT:
-               if (copy_to_user((void *)arg, &jsf0.id, JSFIDSZ))
+               if (copy_to_user(argp, &jsf0.id, JSFIDSZ))
                        return -EFAULT;
                break;
        case JSFLASH_ERASE:
                error = jsf_ioctl_erase(arg);
                break;
        case JSFLASH_PROGRAM:
-               error = jsf_ioctl_program(arg);
+               error = jsf_ioctl_program(argp);
                break;
        }
 
@@ -416,11 +418,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma)
 
 static int jsf_open(struct inode * inode, struct file * filp)
 {
-
-       if (jsf0.base == 0) return -ENXIO;
-       if (test_and_set_bit(0, (void *)&jsf0.busy) != 0)
+       lock_kernel();
+       if (jsf0.base == 0) {
+               unlock_kernel();
+               return -ENXIO;
+       }
+       if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
+       unlock_kernel();
        return 0;       /* XXX What security? */
 }
 
@@ -430,7 +438,7 @@ static int jsf_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static struct file_operations jsf_fops = {
+static const struct file_operations jsf_fops = {
        .owner =        THIS_MODULE,
        .llseek =       jsf_lseek,
        .read =         jsf_read,
@@ -618,8 +626,7 @@ static void __exit jsflash_cleanup_module(void)
        jsf0.busy = 0;
 
        misc_deregister(&jsf_dev);
-       if (unregister_blkdev(JSFD_MAJOR, "jsfd") != 0)
-               printk("jsfd: cleanup_module failed\n");
+       unregister_blkdev(JSFD_MAJOR, "jsfd");
        blk_cleanup_queue(jsf_queue);
 }