* [PATCH v2] x86/mtrr: Convert to use match_string() helper
@ 2018-05-15 17:57 Andy Shevchenko
2018-05-16 10:33 ` [tip:x86/mm] " tip-bot for Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2018-05-15 17:57 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, x86, linux-kernel
Cc: Andy Shevchenko
The helper returns index of the matching string in an array.
Replace the open coded array lookup.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
- reword commit message
arch/x86/kernel/cpu/mtrr/if.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index d0fd1a5a098e..3cbae60663fa 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -137,17 +137,16 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return -EINVAL;
ptr = skip_spaces(ptr + 5);
- for (i = 0; i < MTRR_NUM_TYPES; ++i) {
- if (strcmp(ptr, mtrr_strings[i]))
- continue;
- base >>= PAGE_SHIFT;
- size >>= PAGE_SHIFT;
- err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
- if (err < 0)
- return err;
- return len;
- }
- return -EINVAL;
+ i = match_string(mtrr_strings, MTRR_NUM_TYPES, ptr);
+ if (i < 0)
+ return i;
+
+ base >>= PAGE_SHIFT;
+ size >>= PAGE_SHIFT;
+ err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
+ if (err < 0)
+ return err;
+ return len;
}
static long
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:x86/mm] x86/mtrr: Convert to use match_string() helper
2018-05-15 17:57 [PATCH v2] x86/mtrr: Convert to use match_string() helper Andy Shevchenko
@ 2018-05-16 10:33 ` tip-bot for Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Andy Shevchenko @ 2018-05-16 10:33 UTC (permalink / raw)
To: linux-tip-commits
Cc: akpm, andriy.shevchenko, dvlasenk, toshi.kani, linux-kernel,
mingo, mcgrof, bp, peterz, tglx, luto, torvalds, jpoimboe,
brgerst, hpa
Commit-ID: 13a4db9d75ec5dbca4bd6229e149e061ef7a6bf0
Gitweb: https://git.kernel.org/tip/13a4db9d75ec5dbca4bd6229e149e061ef7a6bf0
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
AuthorDate: Tue, 15 May 2018 20:57:59 +0300
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 16 May 2018 09:47:22 +0200
x86/mtrr: Convert to use match_string() helper
The helper returns index of the matching string in an array.
Replace the open coded array lookup with match_string().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Toshi Kani <toshi.kani@hp.com>
Link: http://lkml.kernel.org/r/20180515175759.89315-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/cpu/mtrr/if.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index 558444b23923..42b4f2f3b557 100644
--- a/arch/x86/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
@@ -149,17 +149,16 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
return -EINVAL;
ptr = skip_spaces(ptr + 5);
- for (i = 0; i < MTRR_NUM_TYPES; ++i) {
- if (strcmp(ptr, mtrr_strings[i]))
- continue;
- base >>= PAGE_SHIFT;
- size >>= PAGE_SHIFT;
- err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
- if (err < 0)
- return err;
- return len;
- }
- return -EINVAL;
+ i = match_string(mtrr_strings, MTRR_NUM_TYPES, ptr);
+ if (i < 0)
+ return i;
+
+ base >>= PAGE_SHIFT;
+ size >>= PAGE_SHIFT;
+ err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
+ if (err < 0)
+ return err;
+ return len;
}
static long
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-16 10:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 17:57 [PATCH v2] x86/mtrr: Convert to use match_string() helper Andy Shevchenko
2018-05-16 10:33 ` [tip:x86/mm] " tip-bot for 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).