From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/2] x86/mtrr: Make use of macros from mm.h
Date: Mon, 9 Dec 2019 19:42:47 +0200 [thread overview]
Message-ID: <20191209174248.45342-1-andriy.shevchenko@linux.intel.com> (raw)
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
next reply other threads:[~2019-12-09 17:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-09 17:42 Andy Shevchenko [this message]
2019-12-09 17:42 ` [PATCH v1 2/2] x86/mtrr: Use strstrip() to cut extra spaces Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191209174248.45342-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome