Commit 26dc67ed authored by Jaswinder Singh Rajput's avatar Jaswinder Singh Rajput Committed by Ingo Molnar

x86: Clean up mtrr/if.c

Fix:

  WARNING: Use #include <linux/uaccess.h> instead of <asm/uaccess.h>
  ERROR: trailing whitespace X 7
  ERROR: trailing statements should be on next line X 3
  WARNING: line over 80 characters X 5
  ERROR: space required before the open parenthesis '('

arch/x86/kernel/cpu/mtrr/if.o:

   text	   data	    bss	    dec	    hex	filename
   2239	      4	      0	   2243	    8c3	if.o.before
   2239	      4	      0	   2243	    8c3	if.o.after

md5:
   78d1f2aa4843ec6509c18e2dee54bc7f  if.o.before.asm
   78d1f2aa4843ec6509c18e2dee54bc7f  if.o.after.asm
Suggested-by: default avatarAlan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarJaswinder Singh Rajput <jaswinderrajput@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yinghai Lu <yinghai@kernel.org>
LKML-Reference: <20090703164225.GA21447@elte.hu>
[ More cleanups to make the code more consistent. ]
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent a1a499a3
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/seq_file.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/init.h>
#define LINE_SIZE 80 #define LINE_SIZE 80
#include <asm/mtrr.h> #include <asm/mtrr.h>
#include "mtrr.h" #include "mtrr.h"
#define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private) #define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private)
...@@ -35,8 +36,8 @@ static int ...@@ -35,8 +36,8 @@ static int
mtrr_file_add(unsigned long base, unsigned long size, mtrr_file_add(unsigned long base, unsigned long size,
unsigned int type, bool increment, struct file *file, int page) unsigned int type, bool increment, struct file *file, int page)
{ {
int reg, max;
unsigned int *fcount = FILE_FCOUNT(file); unsigned int *fcount = FILE_FCOUNT(file);
int reg, max;
max = num_var_ranges; max = num_var_ranges;
if (fcount == NULL) { if (fcount == NULL) {
...@@ -61,8 +62,8 @@ static int ...@@ -61,8 +62,8 @@ static int
mtrr_file_del(unsigned long base, unsigned long size, mtrr_file_del(unsigned long base, unsigned long size,
struct file *file, int page) struct file *file, int page)
{ {
int reg;
unsigned int *fcount = FILE_FCOUNT(file); unsigned int *fcount = FILE_FCOUNT(file);
int reg;
if (!page) { if (!page) {
if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
...@@ -81,13 +82,14 @@ mtrr_file_del(unsigned long base, unsigned long size, ...@@ -81,13 +82,14 @@ mtrr_file_del(unsigned long base, unsigned long size,
return reg; 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 static ssize_t
mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) 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; int i, err;
unsigned long reg; unsigned long reg;
...@@ -100,15 +102,18 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) ...@@ -100,15 +102,18 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return -EPERM; return -EPERM;
if (!len) if (!len)
return -EINVAL; return -EINVAL;
memset(line, 0, LINE_SIZE); memset(line, 0, LINE_SIZE);
if (len > LINE_SIZE) if (len > LINE_SIZE)
len = LINE_SIZE; len = LINE_SIZE;
if (copy_from_user(line, buf, len - 1)) if (copy_from_user(line, buf, len - 1))
return -EFAULT; return -EFAULT;
linelen = strlen(line); linelen = strlen(line);
ptr = line + linelen - 1; ptr = line + linelen - 1;
if (linelen && *ptr == '\n') if (linelen && *ptr == '\n')
*ptr = '\0'; *ptr = '\0';
if (!strncmp(line, "disable=", 8)) { if (!strncmp(line, "disable=", 8)) {
reg = simple_strtoul(line + 8, &ptr, 0); reg = simple_strtoul(line + 8, &ptr, 0);
err = mtrr_del_page(reg, 0, 0); err = mtrr_del_page(reg, 0, 0);
...@@ -116,28 +121,35 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) ...@@ -116,28 +121,35 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return err; return err;
return len; return len;
} }
if (strncmp(line, "base=", 5)) if (strncmp(line, "base=", 5))
return -EINVAL; return -EINVAL;
base = simple_strtoull(line + 5, &ptr, 0); base = simple_strtoull(line + 5, &ptr, 0);
for (; isspace(*ptr); ++ptr) ; for (; isspace(*ptr); ++ptr)
;
if (strncmp(ptr, "size=", 5)) if (strncmp(ptr, "size=", 5))
return -EINVAL; return -EINVAL;
size = simple_strtoull(ptr + 5, &ptr, 0); size = simple_strtoull(ptr + 5, &ptr, 0);
if ((base & 0xfff) || (size & 0xfff)) if ((base & 0xfff) || (size & 0xfff))
return -EINVAL; return -EINVAL;
for (; isspace(*ptr); ++ptr) ; for (; isspace(*ptr); ++ptr)
;
if (strncmp(ptr, "type=", 5)) if (strncmp(ptr, "type=", 5))
return -EINVAL; return -EINVAL;
ptr += 5; ptr += 5;
for (; isspace(*ptr); ++ptr) ; for (; isspace(*ptr); ++ptr)
;
for (i = 0; i < MTRR_NUM_TYPES; ++i) { for (i = 0; i < MTRR_NUM_TYPES; ++i) {
if (strcmp(ptr, mtrr_strings[i])) if (strcmp(ptr, mtrr_strings[i]))
continue; continue;
base >>= PAGE_SHIFT; base >>= PAGE_SHIFT;
size >>= PAGE_SHIFT; size >>= PAGE_SHIFT;
err = err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
mtrr_add_page((unsigned long) base, (unsigned long) size, i,
true);
if (err < 0) if (err < 0)
return err; return err;
return len; return len;
...@@ -181,7 +193,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -181,7 +193,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
case MTRRIOC32_SET_PAGE_ENTRY: case MTRRIOC32_SET_PAGE_ENTRY:
case MTRRIOC32_DEL_PAGE_ENTRY: case MTRRIOC32_DEL_PAGE_ENTRY:
case MTRRIOC32_KILL_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.base, &s32->base);
err |= get_user(sentry.size, &s32->size); err |= get_user(sentry.size, &s32->size);
err |= get_user(sentry.type, &s32->type); err |= get_user(sentry.type, &s32->type);
...@@ -191,7 +205,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -191,7 +205,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
} }
case MTRRIOC32_GET_ENTRY: case MTRRIOC32_GET_ENTRY:
case MTRRIOC32_GET_PAGE_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.regnum, &g32->regnum);
err |= get_user(gentry.base, &g32->base); err |= get_user(gentry.base, &g32->base);
err |= get_user(gentry.size, &g32->size); err |= get_user(gentry.size, &g32->size);
...@@ -314,7 +330,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -314,7 +330,7 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
if (err) if (err)
return err; return err;
switch(cmd) { switch (cmd) {
case MTRRIOC_GET_ENTRY: case MTRRIOC_GET_ENTRY:
case MTRRIOC_GET_PAGE_ENTRY: case MTRRIOC_GET_PAGE_ENTRY:
if (copy_to_user(arg, &gentry, sizeof gentry)) if (copy_to_user(arg, &gentry, sizeof gentry))
...@@ -323,7 +339,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -323,7 +339,9 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case MTRRIOC32_GET_ENTRY: case MTRRIOC32_GET_ENTRY:
case MTRRIOC32_GET_PAGE_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.base, &g32->base);
err |= put_user(gentry.size, &g32->size); err |= put_user(gentry.size, &g32->size);
err |= put_user(gentry.regnum, &g32->regnum); err |= put_user(gentry.regnum, &g32->regnum);
...@@ -335,11 +353,10 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg) ...@@ -335,11 +353,10 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
return err; return err;
} }
static int static int mtrr_close(struct inode *ino, struct file *file)
mtrr_close(struct inode *ino, struct file *file)
{ {
int i, max;
unsigned int *fcount = FILE_FCOUNT(file); unsigned int *fcount = FILE_FCOUNT(file);
int i, max;
if (fcount != NULL) { if (fcount != NULL) {
max = num_var_ranges; max = num_var_ranges;
...@@ -388,9 +405,10 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset) ...@@ -388,9 +405,10 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
max = num_var_ranges; max = num_var_ranges;
for (i = 0; i < max; i++) { for (i = 0; i < max; i++) {
mtrr_if->get(i, &base, &size, &type); mtrr_if->get(i, &base, &size, &type);
if (size == 0) if (size == 0) {
mtrr_usage_table[i] = 0; mtrr_usage_table[i] = 0;
else { continue;
}
if (size < (0x100000 >> PAGE_SHIFT)) { if (size < (0x100000 >> PAGE_SHIFT)) {
/* less than 1MB */ /* less than 1MB */
factor = 'K'; factor = 'K';
...@@ -399,12 +417,12 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset) ...@@ -399,12 +417,12 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
factor = 'M'; factor = 'M';
size >>= 20 - PAGE_SHIFT; size >>= 20 - PAGE_SHIFT;
} }
/* RED-PEN: base can be > 32bit */ /* Base can be > 32bit */
len += seq_printf(seq, len += seq_printf(seq, "reg%02i: base=0x%06lx000 "
"reg%02i: base=0x%06lx000 (%5luMB), size=%5lu%cB, count=%d: %s\n", "(%5luMB), size=%5lu%cB, count=%d: %s\n",
i, base, base >> (20 - PAGE_SHIFT), size, factor, i, base, base >> (20 - PAGE_SHIFT), size,
mtrr_usage_table[i], mtrr_attrib_to_str(type)); factor, mtrr_usage_table[i],
} mtrr_attrib_to_str(type));
} }
return 0; return 0;
} }
...@@ -422,6 +440,5 @@ static int __init mtrr_if_init(void) ...@@ -422,6 +440,5 @@ static int __init mtrr_if_init(void)
proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops); proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
return 0; return 0;
} }
arch_initcall(mtrr_if_init); arch_initcall(mtrr_if_init);
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment