[PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h

From: Andy Shevchenko
Date: Mon Dec 09 2019 - 12:42:53 EST


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@xxxxxxxxxxxxxxx>
---
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