rtl8192e: switch to proc_create()
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 31 Mar 2013 19:02:51 +0000 (15:02 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 9 Apr 2013 18:13:06 +0000 (14:13 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/staging/rtl8192e/rtllib_module.c

index 40b6d809e01e9621d5dfe505507d5b7cda161495..84ea721d5d8e09d5e86fca6555fe6497aaabbb83 100644 (file)
@@ -208,39 +208,34 @@ static int debug = \
                            ;
 static struct proc_dir_entry *rtllib_proc;
 
-static int show_debug_level(char *page, char **start, off_t offset,
-                           int count, int *eof, void *data)
+static int show_debug_level(struct seq_file *m, void *v)
 {
-       return snprintf(page, count, "0x%08X\n", rtllib_debug_level);
+       return seq_printf(m, "0x%08X\n", rtllib_debug_level);
 }
 
-static int store_debug_level(struct file *file, const char __user *buffer,
-                            unsigned long count, void *data)
+static ssize_t write_debug_level(struct file *file, const char __user *buffer,
+                            size_t count, loff_t *ppos)
 {
-       char buf[] = "0x00000000";
-       unsigned long len = min((unsigned long)sizeof(buf) - 1, count);
-       char *p = (char *)buf;
        unsigned long val;
+       int err = kstrtoul_from_user(buffer, count, 0, &val);
+       if (err)
+               return err;
+       rtllib_debug_level = val;
+       return count;
+}
 
-       if (copy_from_user(buf, buffer, len))
-               return count;
-       buf[len] = 0;
-       if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
-               p++;
-               if (p[0] == 'x' || p[0] == 'X')
-                       p++;
-               val = simple_strtoul(p, &p, 16);
-       } else
-               val = simple_strtoul(p, &p, 10);
-       if (p == buf)
-               printk(KERN_INFO DRV_NAME
-                      ": %s is not in hex or decimal form.\n", buf);
-       else
-               rtllib_debug_level = val;
-
-       return strnlen(buf, count);
+static int open_debug_level(struct inode *inode, struct file *file)
+{
+       return single_open(file, show_debug_level, NULL);
 }
 
+static const struct file_operations fops = {
+       .open = open_debug_level,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .write = write_debug_level
+};
+
 int __init rtllib_init(void)
 {
        struct proc_dir_entry *e;
@@ -252,17 +247,12 @@ int __init rtllib_init(void)
                                " proc directory\n");
                return -EIO;
        }
-       e = create_proc_entry("debug_level", S_IFREG | S_IRUGO | S_IWUSR,
-                             rtllib_proc);
+       e = proc_create("debug_level", S_IRUGO | S_IWUSR, rtllib_proc, &fops);
        if (!e) {
                remove_proc_entry(DRV_NAME, init_net.proc_net);
                rtllib_proc = NULL;
                return -EIO;
        }
-       e->read_proc = show_debug_level;
-       e->write_proc = store_debug_level;
-       e->data = NULL;
-
        return 0;
 }