* [PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h
@ 2019-12-09 17:42 Andy Shevchenko
2019-12-09 17:42 ` [PATCH v1 2/2] x86/mtrr: Use strstrip() to cut extra spaces Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2019-12-09 17:42 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
H. Peter Anvin, linux-kernel
Cc: Andy Shevchenko
Use predefined macros from mm.h instead of open coded PAGE_ALIGNED()
and PFN_DOWN(). This will show explicitly the meaning of the operations.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
arch/x86/kernel/cpu/mtrr/if.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index 4d36dcc1cf87..a51eb8e4c079 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -2,6 +2,7 @@
#include <linux/capability.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
+#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
#include <linux/string.h>
@@ -49,10 +50,10 @@ mtrr_file_add(unsigned long base, unsigned long size,
FILE_FCOUNT(file) = fcount;
}
if (!page) {
- if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
+ if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
return -EINVAL;
- base >>= PAGE_SHIFT;
- size >>= PAGE_SHIFT;
+ base = PFN_DOWN(base);
+ size = PFN_DOWN(size);
}
reg = mtrr_add_page(base, size, type, true);
if (reg >= 0)
@@ -68,10 +69,10 @@ mtrr_file_del(unsigned long base, unsigned long size,
int reg;
if (!page) {
- if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
+ if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
return -EINVAL;
- base >>= PAGE_SHIFT;
- size >>= PAGE_SHIFT;
+ base = PFN_DOWN(base);
+ size = PFN_DOWN(size);
}
reg = mtrr_del_page(-1, base, size);
if (reg < 0)
@@ -134,7 +135,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return -EINVAL;
size = simple_strtoull(ptr + 5, &ptr, 0);
- if ((base & 0xfff) || (size & 0xfff))
+ if (!PAGE_ALIGNED(base) || !PAGE_ALIGNED(size))
return -EINVAL;
ptr = skip_spaces(ptr);
@@ -146,8 +147,8 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
if (i < 0)
return i;
- base >>= PAGE_SHIFT;
- size >>= PAGE_SHIFT;
+ base = PFN_DOWN(base);
+ size = PFN_DOWN(size);
err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
if (err < 0)
return err;
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v1 2/2] x86/mtrr: Use strstrip() to cut extra spaces
2019-12-09 17:42 [PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h Andy Shevchenko
@ 2019-12-09 17:42 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2019-12-09 17:42 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
H. Peter Anvin, linux-kernel
Cc: Andy Shevchenko
Cut all white spaces surrounding the passed line.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
arch/x86/kernel/cpu/mtrr/if.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index a51eb8e4c079..9d251efdf064 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -97,10 +97,9 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
int i, err;
unsigned long reg;
unsigned long long base, size;
- char *ptr;
+ char *ptr, *l;
char line[LINE_SIZE];
int length;
- size_t linelen;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -112,23 +111,20 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
if (length < 0)
return length;
- linelen = strlen(line);
- ptr = line + linelen - 1;
- if (linelen && *ptr == '\n')
- *ptr = '\0';
+ l = strstrip(line);
- if (!strncmp(line, "disable=", 8)) {
- reg = simple_strtoul(line + 8, &ptr, 0);
+ if (!strncmp(l, "disable=", 8)) {
+ reg = simple_strtoul(l + 8, &ptr, 0);
err = mtrr_del_page(reg, 0, 0);
if (err < 0)
return err;
return len;
}
- if (strncmp(line, "base=", 5))
+ if (strncmp(l, "base=", 5))
return -EINVAL;
- base = simple_strtoull(line + 5, &ptr, 0);
+ base = simple_strtoull(l + 5, &ptr, 0);
ptr = skip_spaces(ptr);
if (strncmp(ptr, "size=", 5))
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-12-09 18:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 17:42 [PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h Andy Shevchenko
2019-12-09 17:42 ` [PATCH v1 2/2] x86/mtrr: Use strstrip() to cut extra spaces Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).