Skip to contentSkip to conversation

x86/mtrr: Convert to use match_string() helper

PATCH Superseded Andy Shevchenko 3 participants 3 messages May 3, 2018 – May 13, 2018 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

---
 arch/x86/kernel/cpu/mtrr/if.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +10 -11
index 558444b23923..42b4f2f3b557 100644
@@ -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
#1 lore raw
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

#2 lore raw
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