x86/mtrr: Make use of macros from mm.h
PATCH 1/2 x86/mtrr: Make use of macros from mm.h
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 <[email protected]>
--- arch/x86/kernel/cpu/mtrr/if.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +10 -9
@@ -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;
Signature · 1 line
2.24.0
PATCH 2/2 x86/mtrr: Use strstrip() to cut extra spaces
Cut all white spaces surrounding the passed line.
Signed-off-by Andy Shevchenko <[email protected]>
--- arch/x86/kernel/cpu/mtrr/if.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +6 -10
@@ -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 ))
Signature · 1 line
2.24.0