tree-wide: convert open calls to remove spaces to skip_spaces() lib function
[safe/jmp/linux-2.6] / arch / um / drivers / mconsole_kern.c
index c953e14..5106924 100644 (file)
@@ -1,23 +1,28 @@
 /*
  * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
- * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Copyright (C) 2001 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
-#include "linux/console.h"
-#include "linux/ctype.h"
-#include "linux/interrupt.h"
-#include "linux/list.h"
-#include "linux/mm.h"
-#include "linux/module.h"
-#include "linux/notifier.h"
-#include "linux/reboot.h"
-#include "linux/proc_fs.h"
-#include "linux/slab.h"
-#include "linux/syscalls.h"
-#include "linux/utsname.h"
-#include "linux/workqueue.h"
-#include "asm/uaccess.h"
+#include <linux/console.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/utsname.h>
+#include <linux/socket.h>
+#include <linux/un.h>
+#include <linux/workqueue.h>
+#include <linux/mutex.h>
+#include <asm/uaccess.h>
+
 #include "init.h"
 #include "irq_kern.h"
 #include "irq_user.h"
@@ -127,7 +132,7 @@ void mconsole_proc(struct mc_request *req)
        char *ptr = req->request.data, *buf;
 
        ptr += strlen("proc");
-       while (isspace(*ptr)) ptr++;
+       ptr = skip_spaces(ptr);
 
        proc = get_fs_type("proc");
        if (proc == NULL) {
@@ -143,8 +148,8 @@ void mconsole_proc(struct mc_request *req)
        }
        up_write(&super->s_umount);
 
-       nd.dentry = super->s_root;
-       nd.mnt = NULL;
+       nd.path.dentry = super->s_root;
+       nd.path.mnt = NULL;
        nd.flags = O_RDONLY + 1;
        nd.last_type = LAST_ROOT;
 
@@ -157,7 +162,8 @@ void mconsole_proc(struct mc_request *req)
                goto out_kill;
        }
 
-       file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
+       file = dentry_open(nd.path.dentry, nd.path.mnt, O_RDONLY,
+                          current_cred());
        if (IS_ERR(file)) {
                mconsole_reply(req, "Failed to open file", 1, 0);
                goto out_kill;
@@ -207,8 +213,7 @@ void mconsole_proc(struct mc_request *req)
        char *ptr = req->request.data;
 
        ptr += strlen("proc");
-       while (isspace(*ptr))
-               ptr++;
+       ptr = skip_spaces(ptr);
        snprintf(path, sizeof(path), "/proc/%s", ptr);
 
        fd = sys_open(path, 0, 0);
@@ -305,7 +310,9 @@ void mconsole_stop(struct mc_request *req)
        deactivate_fd(req->originating_fd, MCONSOLE_IRQ);
        os_set_fd_block(req->originating_fd, 1);
        mconsole_reply(req, "stopped", 0, 0);
-       while (mconsole_get_request(req->originating_fd, req)) {
+       for (;;) {
+               if (!mconsole_get_request(req->originating_fd, req))
+                       continue;
                if (req->cmd->handler == mconsole_go)
                        break;
                if (req->cmd->handler == mconsole_stop) {
@@ -358,7 +365,7 @@ struct unplugged_pages {
        void *pages[UNPLUGGED_PER_PAGE];
 };
 
-static DECLARE_MUTEX(plug_mem_mutex);
+static DEFINE_MUTEX(plug_mem_mutex);
 static unsigned long long unplugged_pages_count = 0;
 static LIST_HEAD(unplugged_pages);
 static int unplug_index = UNPLUGGED_PER_PAGE;
@@ -394,7 +401,7 @@ static int mem_config(char *str, char **error_out)
 
        diff /= PAGE_SIZE;
 
-       down(&plug_mem_mutex);
+       mutex_lock(&plug_mem_mutex);
        for (i = 0; i < diff; i++) {
                struct unplugged_pages *unplugged;
                void *addr;
@@ -451,7 +458,7 @@ static int mem_config(char *str, char **error_out)
 
        err = 0;
 out_unlock:
-       up(&plug_mem_mutex);
+       mutex_unlock(&plug_mem_mutex);
 out:
        return err;
 }
@@ -553,8 +560,7 @@ void mconsole_config(struct mc_request *req)
        int err;
 
        ptr += strlen("config");
-       while (isspace(*ptr))
-               ptr++;
+       ptr = skip_spaces(ptr);
        dev = mconsole_find_dev(ptr);
        if (dev == NULL) {
                mconsole_reply(req, "Bad configuration option", 1, 0);
@@ -581,7 +587,7 @@ void mconsole_remove(struct mc_request *req)
        int err, start, end, n;
 
        ptr += strlen("remove");
-       while (isspace(*ptr)) ptr++;
+       ptr = skip_spaces(ptr);
        dev = mconsole_find_dev(ptr);
        if (dev == NULL) {
                mconsole_reply(req, "Bad remove option", 1, 0);
@@ -705,7 +711,7 @@ void mconsole_sysrq(struct mc_request *req)
        char *ptr = req->request.data;
 
        ptr += strlen("sysrq");
-       while (isspace(*ptr)) ptr++;
+       ptr = skip_spaces(ptr);
 
        /*
         * With 'b', the system will shut down without a chance to reply,
@@ -750,8 +756,7 @@ void mconsole_stack(struct mc_request *req)
         */
 
        ptr += strlen("stack");
-       while (isspace(*ptr))
-               ptr++;
+       ptr = skip_spaces(ptr);
 
        /*
         * Should really check for multiple pids or reject bad args here
@@ -762,7 +767,7 @@ void mconsole_stack(struct mc_request *req)
                return;
        }
 
-       to = find_task_by_pid(pid_requested);
+       to = find_task_by_pid_ns(pid_requested, &init_pid_ns);
        if ((to == NULL) || (pid_requested == 0)) {
                mconsole_reply(req, "Couldn't find that pid", 1, 0);
                return;
@@ -781,7 +786,7 @@ static int __init mconsole_init(void)
        /* long to avoid size mismatch warnings from gcc */
        long sock;
        int err;
-       char file[256];
+       char file[UNIX_PATH_MAX];
 
        if (umid_file_name("mconsole", file, sizeof(file)))
                return -1;
@@ -826,8 +831,8 @@ static int __init mconsole_init(void)
 
 __initcall(mconsole_init);
 
-static int write_proc_mconsole(struct file *file, const char __user *buffer,
-                              unsigned long count, void *data)
+static ssize_t mconsole_proc_write(struct file *file,
+               const char __user *buffer, size_t count, loff_t *pos)
 {
        char *buf;
 
@@ -848,6 +853,11 @@ static int write_proc_mconsole(struct file *file, const char __user *buffer,
        return count;
 }
 
+static const struct file_operations mconsole_proc_fops = {
+       .owner          = THIS_MODULE,
+       .write          = mconsole_proc_write,
+};
+
 static int create_proc_mconsole(void)
 {
        struct proc_dir_entry *ent;
@@ -855,15 +865,12 @@ static int create_proc_mconsole(void)
        if (notify_socket == NULL)
                return 0;
 
-       ent = create_proc_entry("mconsole", S_IFREG | 0200, NULL);
+       ent = proc_create("mconsole", 0200, NULL, &mconsole_proc_fops);
        if (ent == NULL) {
                printk(KERN_INFO "create_proc_mconsole : create_proc_entry "
                       "failed\n");
                return 0;
        }
-
-       ent->read_proc = NULL;
-       ent->write_proc = write_proc_mconsole;
        return 0;
 }