include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / x86 / kernel / cpu / mtrr / if.c
index 84c480b..7928963 100644 (file)
@@ -1,27 +1,30 @@
-#include <linux/init.h>
-#include <linux/proc_fs.h>
 #include <linux/capability.h>
-#include <linux/ctype.h>
-#include <linux/module.h>
 #include <linux/seq_file.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
+#include <linux/proc_fs.h>
+#include <linux/module.h>
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/init.h>
 
 #define LINE_SIZE 80
 
 #include <asm/mtrr.h>
+
 #include "mtrr.h"
 
 #define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private)
 
 static const char *const mtrr_strings[MTRR_NUM_TYPES] =
 {
-    "uncachable",               /* 0 */
-    "write-combining",          /* 1 */
-    "?",                        /* 2 */
-    "?",                        /* 3 */
-    "write-through",            /* 4 */
-    "write-protect",            /* 5 */
-    "write-back",               /* 6 */
+       "uncachable",           /* 0 */
+       "write-combining",      /* 1 */
+       "?",                    /* 2 */
+       "?",                    /* 3 */
+       "write-through",        /* 4 */
+       "write-protect",        /* 5 */
+       "write-back",           /* 6 */
 };
 
 const char *mtrr_attrib_to_str(int x)
@@ -35,8 +38,8 @@ static int
 mtrr_file_add(unsigned long base, unsigned long size,
              unsigned int type, bool increment, struct file *file, int page)
 {
+       unsigned int *fcount = FILE_FCOUNT(file);
        int reg, max;
-       unsigned int *fcount = FILE_FCOUNT(file); 
 
        max = num_var_ranges;
        if (fcount == NULL) {
@@ -61,8 +64,8 @@ static int
 mtrr_file_del(unsigned long base, unsigned long size,
              struct file *file, int page)
 {
-       int reg;
        unsigned int *fcount = FILE_FCOUNT(file);
+       int reg;
 
        if (!page) {
                if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
@@ -81,34 +84,45 @@ mtrr_file_del(unsigned long base, unsigned long size,
        return reg;
 }
 
-/* RED-PEN: seq_file can seek now. this is ignored. */
+/*
+ * seq_file can seek but we ignore it.
+ *
+ * Format of control line:
+ *    "base=%Lx size=%Lx type=%s" or "disable=%d"
+ */
 static ssize_t
 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
-/*  Format of control line:
-    "base=%Lx size=%Lx type=%s"     OR:
-    "disable=%d"
-*/
 {
        int i, err;
        unsigned long reg;
        unsigned long long base, size;
        char *ptr;
        char line[LINE_SIZE];
+       int length;
        size_t linelen;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
-       if (!len)
-               return -EINVAL;
+
        memset(line, 0, LINE_SIZE);
-       if (len > LINE_SIZE)
-               len = LINE_SIZE;
-       if (copy_from_user(line, buf, len - 1))
+
+       length = len;
+       length--;
+
+       if (length > LINE_SIZE - 1)
+               length = LINE_SIZE - 1;
+
+       if (length < 0)
+               return -EINVAL;
+
+       if (copy_from_user(line, buf, length))
                return -EFAULT;
+
        linelen = strlen(line);
        ptr = line + linelen - 1;
        if (linelen && *ptr == '\n')
                *ptr = '\0';
+
        if (!strncmp(line, "disable=", 8)) {
                reg = simple_strtoul(line + 8, &ptr, 0);
                err = mtrr_del_page(reg, 0, 0);
@@ -116,28 +130,31 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
                        return err;
                return len;
        }
+
        if (strncmp(line, "base=", 5))
                return -EINVAL;
+
        base = simple_strtoull(line + 5, &ptr, 0);
-       for (; isspace(*ptr); ++ptr) ;
+       ptr = skip_spaces(ptr);
+
        if (strncmp(ptr, "size=", 5))
                return -EINVAL;
+
        size = simple_strtoull(ptr + 5, &ptr, 0);
        if ((base & 0xfff) || (size & 0xfff))
                return -EINVAL;
-       for (; isspace(*ptr); ++ptr) ;
+       ptr = skip_spaces(ptr);
+
        if (strncmp(ptr, "type=", 5))
                return -EINVAL;
-       ptr += 5;
-       for (; isspace(*ptr); ++ptr) ;
+       ptr = skip_spaces(ptr + 5);
+
        for (i = 0; i < MTRR_NUM_TYPES; ++i) {
                if (strcmp(ptr, mtrr_strings[i]))
                        continue;
                base >>= PAGE_SHIFT;
                size >>= PAGE_SHIFT;
-               err =
-                   mtrr_add_page((unsigned long) base, (unsigned long) size, i,
-                                 true);
+               err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
                if (err < 0)
                        return err;
                return len;
@@ -181,7 +198,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
        case MTRRIOC32_SET_PAGE_ENTRY:
        case MTRRIOC32_DEL_PAGE_ENTRY:
        case MTRRIOC32_KILL_PAGE_ENTRY: {
-               struct mtrr_sentry32 __user *s32 = (struct mtrr_sentry32 __user *)__arg;
+               struct mtrr_sentry32 __user *s32;
+
+               s32 = (struct mtrr_sentry32 __user *)__arg;
                err = get_user(sentry.base, &s32->base);
                err |= get_user(sentry.size, &s32->size);
                err |= get_user(sentry.type, &s32->type);
@@ -191,7 +210,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
        }
        case MTRRIOC32_GET_ENTRY:
        case MTRRIOC32_GET_PAGE_ENTRY: {
-               struct mtrr_gentry32 __user *g32 = (struct mtrr_gentry32 __user *)__arg;
+               struct mtrr_gentry32 __user *g32;
+
+               g32 = (struct mtrr_gentry32 __user *)__arg;
                err = get_user(gentry.regnum, &g32->regnum);
                err |= get_user(gentry.base, &g32->base);
                err |= get_user(gentry.size, &g32->size);
@@ -314,7 +335,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
        if (err)
                return err;
 
-       switch(cmd) {
+       switch (cmd) {
        case MTRRIOC_GET_ENTRY:
        case MTRRIOC_GET_PAGE_ENTRY:
                if (copy_to_user(arg, &gentry, sizeof gentry))
@@ -323,7 +344,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
 #ifdef CONFIG_COMPAT
        case MTRRIOC32_GET_ENTRY:
        case MTRRIOC32_GET_PAGE_ENTRY: {
-               struct mtrr_gentry32 __user *g32 = (struct mtrr_gentry32 __user *)__arg;
+               struct mtrr_gentry32 __user *g32;
+
+               g32 = (struct mtrr_gentry32 __user *)__arg;
                err = put_user(gentry.base, &g32->base);
                err |= put_user(gentry.size, &g32->size);
                err |= put_user(gentry.regnum, &g32->regnum);
@@ -335,11 +358,10 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
        return err;
 }
 
-static int
-mtrr_close(struct inode *ino, struct file *file)
+static int mtrr_close(struct inode *ino, struct file *file)
 {
-       int i, max;
        unsigned int *fcount = FILE_FCOUNT(file);
+       int i, max;
 
        if (fcount != NULL) {
                max = num_var_ranges;
@@ -359,28 +381,24 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset);
 
 static int mtrr_open(struct inode *inode, struct file *file)
 {
-       if (!mtrr_if) 
+       if (!mtrr_if)
                return -EIO;
-       if (!mtrr_if->get) 
-               return -ENXIO; 
+       if (!mtrr_if->get)
+               return -ENXIO;
        return single_open(file, mtrr_seq_show, NULL);
 }
 
 static const struct file_operations mtrr_fops = {
-       .owner   = THIS_MODULE,
-       .open    = mtrr_open, 
-       .read    = seq_read,
-       .llseek  = seq_lseek,
-       .write   = mtrr_write,
-       .unlocked_ioctl = mtrr_ioctl,
-       .compat_ioctl = mtrr_ioctl,
-       .release = mtrr_close,
+       .owner                  = THIS_MODULE,
+       .open                   = mtrr_open,
+       .read                   = seq_read,
+       .llseek                 = seq_lseek,
+       .write                  = mtrr_write,
+       .unlocked_ioctl         = mtrr_ioctl,
+       .compat_ioctl           = mtrr_ioctl,
+       .release                = mtrr_close,
 };
 
-
-static struct proc_dir_entry *proc_root_mtrr;
-
-
 static int mtrr_seq_show(struct seq_file *seq, void *offset)
 {
        char factor;
@@ -392,23 +410,24 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
        max = num_var_ranges;
        for (i = 0; i < max; i++) {
                mtrr_if->get(i, &base, &size, &type);
-               if (size == 0)
+               if (size == 0) {
                        mtrr_usage_table[i] = 0;
-               else {
-                       if (size < (0x100000 >> PAGE_SHIFT)) {
-                               /* less than 1MB */
-                               factor = 'K';
-                               size <<= PAGE_SHIFT - 10;
-                       } else {
-                               factor = 'M';
-                               size >>= 20 - PAGE_SHIFT;
-                       }
-                       /* RED-PEN: base can be > 32bit */ 
-                       len += seq_printf(seq, 
-                                  "reg%02i: base=0x%05lx000 (%4luMB), size=%4lu%cB: %s, count=%d\n",
-                            i, base, base >> (20 - PAGE_SHIFT), size, factor,
-                            mtrr_attrib_to_str(type), mtrr_usage_table[i]);
+                       continue;
+               }
+               if (size < (0x100000 >> PAGE_SHIFT)) {
+                       /* less than 1MB */
+                       factor = 'K';
+                       size <<= PAGE_SHIFT - 10;
+               } else {
+                       factor = 'M';
+                       size >>= 20 - PAGE_SHIFT;
                }
+               /* Base can be > 32bit */
+               len += seq_printf(seq, "reg%02i: base=0x%06lx000 "
+                       "(%5luMB), size=%5lu%cB, count=%d: %s\n",
+                       i, base, base >> (20 - PAGE_SHIFT), size,
+                       factor, mtrr_usage_table[i],
+                       mtrr_attrib_to_str(type));
        }
        return 0;
 }
@@ -423,13 +442,8 @@ static int __init mtrr_if_init(void)
            (!cpu_has(c, X86_FEATURE_CENTAUR_MCR)))
                return -ENODEV;
 
-       proc_root_mtrr =
-               proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
-
-       if (proc_root_mtrr)
-               proc_root_mtrr->owner = THIS_MODULE;
+       proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
        return 0;
 }
-
 arch_initcall(mtrr_if_init);
 #endif                 /*  CONFIG_PROC_FS  */