[PATCH v2 09/11] x86/mm/pat: inline memtype_match() into memtype_erase()
David Hildenbrand
david at redhat.com
Mon May 12 12:34:22 UTC 2025
Let's just have it in a single function. The resulting function is
certainly small enough and readable.
Signed-off-by: David Hildenbrand <david at redhat.com>
---
arch/x86/mm/pat/memtype_interval.c | 33 +++++++++---------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/arch/x86/mm/pat/memtype_interval.c b/arch/x86/mm/pat/memtype_interval.c
index 9d03f0dbc4715..e5844ed1311ed 100644
--- a/arch/x86/mm/pat/memtype_interval.c
+++ b/arch/x86/mm/pat/memtype_interval.c
@@ -49,21 +49,6 @@ INTERVAL_TREE_DEFINE(struct memtype, rb, u64, subtree_max_end,
static struct rb_root_cached memtype_rbroot = RB_ROOT_CACHED;
-static struct memtype *memtype_match(u64 start, u64 end)
-{
- struct memtype *entry_match;
-
- entry_match = interval_iter_first(&memtype_rbroot, start, end-1);
-
- while (entry_match != NULL && entry_match->start < end) {
- if (entry_match->start == start && entry_match->end == end)
- return entry_match;
- entry_match = interval_iter_next(entry_match, start, end-1);
- }
-
- return NULL; /* Returns NULL if there is no match */
-}
-
static int memtype_check_conflict(u64 start, u64 end,
enum page_cache_mode reqtype,
enum page_cache_mode *newtype)
@@ -119,14 +104,16 @@ int memtype_check_insert(struct memtype *entry_new, enum page_cache_mode *ret_ty
struct memtype *memtype_erase(u64 start, u64 end)
{
- struct memtype *entry_old;
-
- entry_old = memtype_match(start, end);
- if (!entry_old)
- return ERR_PTR(-EINVAL);
-
- interval_remove(entry_old, &memtype_rbroot);
- return entry_old;
+ struct memtype *entry = interval_iter_first(&memtype_rbroot, start, end - 1);
+
+ while (entry && entry->start < end) {
+ if (entry->start == start && entry->end == end) {
+ interval_remove(entry, &memtype_rbroot);
+ return entry;
+ }
+ entry = interval_iter_next(entry, start, end - 1);
+ }
+ return ERR_PTR(-EINVAL);
}
struct memtype *memtype_lookup(u64 addr)
--
2.49.0
More information about the Intel-gfx
mailing list