x86/mtrr: Convert to use match_string() helper
PATCH 1/1 x86/mtrr: Convert to use match_string() helper
The new helper returns index of the matching string in an array. We are going to use it here.
Signed-off-by Andy Shevchenko <[email protected]>
--- arch/x86/kernel/cpu/mtrr/if.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +10 -11
@@ -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
Signature · 1 line
2.17.0
Quoted 1 line · Andy Shevchenko
The new helper returns index of the matching string in an array.
new helper? match_string() is in tree for 2 years.
Quoted 1 line
We are going to use it here.
Are we going to use it ? When?
"Replace the open coded array lookup." or something like that would be more appropriate.
Thanks,
tglx
Quoted 5 lines · Thomas Gleixner
Quoted 1 line · Andy Shevchenko
The new helper returns index of the matching string in an array.
new helper?
match_string()is in tree for 2 years.
Old template.
Quoted 6 lines
Quoted 1 line
We are going to use it here.
Are we going to use it ? When?
"Replace the open coded array lookup." or something like that would be more appropriate.
Will change this.
Thanks for review!
Signature · 2 lines
With Best Regards, Andy Shevchenko