include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / char / briq_panel.c
index caae795..555cd93 100644 (file)
@@ -6,16 +6,14 @@
 
 #include <linux/module.h>
 
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
-#include <linux/sched.h>
 #include <linux/tty.h>
 #include <linux/timer.h>
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/wait.h>
 #include <linux/string.h>
-#include <linux/slab.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/miscdevice.h>
@@ -69,11 +67,15 @@ static void set_led(char state)
 
 static int briq_panel_open(struct inode *ino, struct file *filep)
 {
-       /* enforce single access */
-       if (vfd_is_open)
+       lock_kernel();
+       /* enforce single access, vfd_is_open is protected by BKL */
+       if (vfd_is_open) {
+               unlock_kernel();
                return -EBUSY;
+       }
        vfd_is_open = 1;
 
+       unlock_kernel();
        return 0;
 }
 
@@ -87,17 +89,12 @@ static int briq_panel_release(struct inode *ino, struct file *filep)
        return 0;
 }
 
-static ssize_t briq_panel_read(struct file *file, char *buf, size_t count,
+static ssize_t briq_panel_read(struct file *file, char __user *buf, size_t count,
                         loff_t *ppos)
 {
        unsigned short c;
        unsigned char cp;
 
-#if 0  /*  Can't seek (pread) on this device  */
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
-#endif
-
        if (!vfd_is_open)
                return -ENODEV;
 
@@ -135,34 +132,32 @@ static void scroll_vfd( void )
        vfd_cursor = 20;
 }
 
-static ssize_t briq_panel_write(struct file *file, const char *buf, size_t len,
+static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_t len,
                          loff_t *ppos)
 {
        size_t indx = len;
        int i, esc = 0;
 
-#if 0  /*  Can't seek (pwrite) on this device  */
-       if (ppos != &file->f_pos)
-               return -ESPIPE;
-#endif
-
        if (!vfd_is_open)
                return -EBUSY;
 
        for (;;) {
+               char c;
                if (!indx)
                        break;
+               if (get_user(c, buf))
+                       return -EFAULT;
                if (esc) {
-                       set_led(*buf);
+                       set_led(c);
                        esc = 0;
-               } else if (*buf == 27) {
+               } else if (c == 27) {
                        esc = 1;
-               } else if (*buf == 12) {
+               } else if (c == 12) {
                        /* do a form feed */
                        for (i=0; i<40; i++)
                                vfd[i] = ' ';
                        vfd_cursor = 0;
-               } else if (*buf == 10) {
+               } else if (c == 10) {
                        if (vfd_cursor < 20)
                                vfd_cursor = 20;
                        else if (vfd_cursor < 40)
@@ -175,7 +170,7 @@ static ssize_t briq_panel_write(struct file *file, const char *buf, size_t len,
                        /* just a character */
                        if (vfd_cursor > 39)
                                scroll_vfd();
-                       vfd[vfd_cursor++] = *buf;
+                       vfd[vfd_cursor++] = c;
                }
                indx--;
                buf++;
@@ -185,7 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char *buf, size_t len,
        return len;
 }
 
-static struct file_operations briq_panel_fops = {
+static const struct file_operations briq_panel_fops = {
        .owner          = THIS_MODULE,
        .read           = briq_panel_read,
        .write          = briq_panel_write,
@@ -201,13 +196,16 @@ static struct miscdevice briq_panel_miscdev = {
 
 static int __init briq_panel_init(void)
 {
-       struct device_node *root = find_path_device("/");
+       struct device_node *root = of_find_node_by_path("/");
        const char *machine;
        int i;
 
-       machine = get_property(root, "model", NULL);
-       if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0)
+       machine = of_get_property(root, "model", NULL);
+       if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) {
+               of_node_put(root);
                return -ENODEV;
+       }
+       of_node_put(root);
 
        printk(KERN_INFO
                "briq_panel: v%s Dr. Karsten Jeppesen (kj@totalimpact.com)\n",