[PATCH v1 2/2] x86/mtrr: Use strstrip() to cut extra spaces

From: Andy Shevchenko
Date: Mon Dec 09 2019 - 13:00:50 EST


Cut all white spaces surrounding the passed line.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
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