Merge git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-drm-fsl-dcu.git] / arch / um / drivers / harddog_kern.c
index 49acb2badf3229437c7a0149bc3da5be8d7d2109..73c5caa7a150ea1a6757aaa2bfea26b00bc6a771 100644 (file)
@@ -9,10 +9,10 @@
  *     modify it under the terms of the GNU General Public License
  *     as published by the Free Software Foundation; either version
  *     2 of the License, or (at your option) any later version.
- *     
- *     Neither Alan Cox nor CymruNet Ltd. admit liability nor provide 
- *     warranty for any of this software. This material is provided 
- *     "AS-IS" and at no charge.       
+ *
+ *     Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
+ *     warranty for any of this software. This material is provided
+ *     "AS-IS" and at no charge.
  *
  *     (c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Made SMP safe for 2.3.x
  *
  *  20011127 Joel Becker (jlbec@evilplan.org>
- *     Added soft_noboot; Allows testing the softdog trigger without 
+ *     Added soft_noboot; Allows testing the softdog trigger without
  *     requiring a recompile.
  *     Added WDIOC_GETTIMEOUT and WDIOC_SETTIMOUT.
  */
+
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/reboot.h>
 #include <linux/smp_lock.h>
 #include <linux/init.h>
+#include <linux/spinlock.h>
 #include <asm/uaccess.h>
 #include "mconsole.h"
 
 MODULE_LICENSE("GPL");
 
-/* Locked by the BKL in harddog_open and harddog_release */
+static DEFINE_SPINLOCK(lock);
 static int timer_alive;
 static int harddog_in_fd = -1;
 static int harddog_out_fd = -1;
@@ -58,18 +58,18 @@ static int harddog_out_fd = -1;
 /*
  *     Allow only one person to hold it open
  */
+
 extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock);
 
 static int harddog_open(struct inode *inode, struct file *file)
 {
-       int err;
+       int err = -EBUSY;
        char *sock = NULL;
 
-       lock_kernel();
+       spin_lock(&lock);
        if(timer_alive)
-               return -EBUSY;
-#ifdef CONFIG_HARDDOG_NOWAYOUT  
+               goto err;
+#ifdef CONFIG_HARDDOG_NOWAYOUT
        __module_get(THIS_MODULE);
 #endif
 
@@ -77,11 +77,15 @@ static int harddog_open(struct inode *inode, struct file *file)
        sock = mconsole_notify_socket();
 #endif
        err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock);
-       if(err) return(err);
+       if(err)
+               goto err;
 
        timer_alive = 1;
-       unlock_kernel();
+       spin_unlock(&lock);
        return nonseekable_open(inode, file);
+err:
+       spin_unlock(&lock);
+       return err;
 }
 
 extern void stop_watchdog(int in_fd, int out_fd);
@@ -91,33 +95,36 @@ static int harddog_release(struct inode *inode, struct file *file)
        /*
         *      Shut off the timer.
         */
-       lock_kernel();
+
+       spin_lock(&lock);
 
        stop_watchdog(harddog_in_fd, harddog_out_fd);
        harddog_in_fd = -1;
        harddog_out_fd = -1;
 
        timer_alive=0;
-       unlock_kernel();
+       spin_unlock(&lock);
+
        return 0;
 }
 
 extern int ping_watchdog(int fd);
 
-static ssize_t harddog_write(struct file *file, const char *data, size_t len,
+static ssize_t harddog_write(struct file *file, const char __user *data, size_t len,
                             loff_t *ppos)
 {
        /*
         *      Refresh the timer.
         */
        if(len)
-               return(ping_watchdog(harddog_out_fd));
+               return ping_watchdog(harddog_out_fd);
        return 0;
 }
 
 static int harddog_ioctl(struct inode *inode, struct file *file,
                         unsigned int cmd, unsigned long arg)
 {
+       void __user *argp= (void __user *)arg;
        static struct watchdog_info ident = {
                WDIOC_SETTIMEOUT,
                0,
@@ -127,15 +134,14 @@ static int harddog_ioctl(struct inode *inode, struct file *file,
                default:
                        return -ENOTTY;
                case WDIOC_GETSUPPORT:
-                       if(copy_to_user((struct harddog_info *)arg, &ident,
-                                       sizeof(ident)))
+                       if(copy_to_user(argp, &ident, sizeof(ident)))
                                return -EFAULT;
                        return 0;
                case WDIOC_GETSTATUS:
                case WDIOC_GETBOOTSTATUS:
-                       return put_user(0,(int *)arg);
+                       return put_user(0,(int __user *)argp);
                case WDIOC_KEEPALIVE:
-                       return(ping_watchdog(harddog_out_fd));
+                       return ping_watchdog(harddog_out_fd);
        }
 }
 
@@ -166,7 +172,7 @@ static int __init harddog_init(void)
 
        printk(banner);
 
-       return(0);
+       return 0;
 }
 
 static void __exit harddog_exit(void)
@@ -176,14 +182,3 @@ static void __exit harddog_exit(void)
 
 module_init(harddog_init);
 module_exit(harddog_exit);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */