Merge tag 'mm-stable-2024-05-17-19-19' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / dax / kmem.c
index 42ee360cf4e3db86150b2f20db63bf626e601576..4fe9d040e375450d2f02f60ca817bf57fadff3b4 100644 (file)
@@ -55,36 +55,14 @@ static LIST_HEAD(kmem_memory_types);
 
 static struct memory_dev_type *kmem_find_alloc_memory_type(int adist)
 {
-       bool found = false;
-       struct memory_dev_type *mtype;
-
-       mutex_lock(&kmem_memory_type_lock);
-       list_for_each_entry(mtype, &kmem_memory_types, list) {
-               if (mtype->adistance == adist) {
-                       found = true;
-                       break;
-               }
-       }
-       if (!found) {
-               mtype = alloc_memory_type(adist);
-               if (!IS_ERR(mtype))
-                       list_add(&mtype->list, &kmem_memory_types);
-       }
-       mutex_unlock(&kmem_memory_type_lock);
-
-       return mtype;
+       guard(mutex)(&kmem_memory_type_lock);
+       return mt_find_alloc_memory_type(adist, &kmem_memory_types);
 }
 
 static void kmem_put_memory_types(void)
 {
-       struct memory_dev_type *mtype, *mtn;
-
-       mutex_lock(&kmem_memory_type_lock);
-       list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) {
-               list_del(&mtype->list);
-               put_memory_type(mtype);
-       }
-       mutex_unlock(&kmem_memory_type_lock);
+       guard(mutex)(&kmem_memory_type_lock);
+       mt_put_memory_types(&kmem_memory_types);
 }
 
 static int dev_dax_kmem_probe(struct dev_dax *dev_dax)