]> www.infradead.org Git - users/willy/xarray.git/commitdiff
mtdcore: Convert mtd_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 20:27:48 +0000 (15:27 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:17 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/mtd/mtdcore.c
drivers/mtd/mtdcore.h

index 408615f29e57608c356e69a2cc703f997ec6866c..4508c88926a7a10ba3548347221c06f2323f4553 100644 (file)
@@ -66,16 +66,16 @@ static struct class mtd_class = {
        .pm = MTD_CLS_PM_OPS,
 };
 
-static DEFINE_IDR(mtd_idr);
+static DEFINE_XARRAY_ALLOC(mtd_devs);
 
 /* These are exported solely for the purpose of mtd_blkdevs.c. You
    should not use them for _anything_ else */
 DEFINE_MUTEX(mtd_table_mutex);
 EXPORT_SYMBOL_GPL(mtd_table_mutex);
 
-struct mtd_info *__mtd_next_device(int i)
+struct mtd_info *__mtd_next_device(unsigned long i)
 {
-       return idr_get_next(&mtd_idr, &i);
+       return xa_find(&mtd_devs, &i, ULONG_MAX, XA_PRESENT);
 }
 EXPORT_SYMBOL_GPL(__mtd_next_device);
 
@@ -526,7 +526,7 @@ static struct dentry *dfs_dir_mtd;
 int add_mtd_device(struct mtd_info *mtd)
 {
        struct mtd_notifier *not;
-       int i, error;
+       int error;
 
        /*
         * May occur, for instance, on buggy drivers which call
@@ -552,13 +552,10 @@ int add_mtd_device(struct mtd_info *mtd)
 
        mutex_lock(&mtd_table_mutex);
 
-       i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
-       if (i < 0) {
-               error = i;
+       error = xa_alloc(&mtd_devs, &mtd->index, mtd, xa_limit_31b, GFP_KERNEL);
+       if (error < 0)
                goto fail_locked;
-       }
 
-       mtd->index = i;
        mtd->usecount = 0;
 
        /* default value if not set by driver */
@@ -594,8 +591,8 @@ int add_mtd_device(struct mtd_info *mtd)
         */
        mtd->dev.type = &mtd_devtype;
        mtd->dev.class = &mtd_class;
-       mtd->dev.devt = MTD_DEVT(i);
-       dev_set_name(&mtd->dev, "mtd%d", i);
+       mtd->dev.devt = MTD_DEVT(mtd->index);
+       dev_set_name(&mtd->dev, "mtd%d", mtd->index);
        dev_set_drvdata(&mtd->dev, mtd);
        of_node_get(mtd_get_of_node(mtd));
        error = device_register(&mtd->dev);
@@ -615,10 +612,10 @@ int add_mtd_device(struct mtd_info *mtd)
                }
        }
 
-       device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
-                     "mtd%dro", i);
+       device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(mtd->index) + 1, NULL,
+                     "mtd%dro", mtd->index);
 
-       pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
+       pr_debug("mtd: Giving out device %d to %s\n", mtd->index, mtd->name);
        /* No need to get a refcount on the module containing
           the notifier, since we hold the mtd_table_mutex */
        list_for_each_entry(not, &mtd_notifiers, list)
@@ -636,7 +633,7 @@ fail_nvmem_add:
        device_unregister(&mtd->dev);
 fail_added:
        of_node_put(mtd_get_of_node(mtd));
-       idr_remove(&mtd_idr, i);
+       xa_erase(&mtd_devs, mtd->index);
 fail_locked:
        mutex_unlock(&mtd_table_mutex);
        return error;
@@ -661,7 +658,7 @@ int del_mtd_device(struct mtd_info *mtd)
 
        debugfs_remove_recursive(mtd->dbg.dfs_dir);
 
-       if (idr_find(&mtd_idr, mtd->index) != mtd) {
+       if (xa_load(&mtd_devs, mtd->index) != mtd) {
                ret = -ENODEV;
                goto out_error;
        }
@@ -682,7 +679,7 @@ int del_mtd_device(struct mtd_info *mtd)
 
                device_unregister(&mtd->dev);
 
-               idr_remove(&mtd_idr, mtd->index);
+               xa_erase(&mtd_devs, mtd->index);
                of_node_put(mtd_get_of_node(mtd));
 
                module_put(THIS_MODULE);
@@ -893,7 +890,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
                        }
                }
        } else if (num >= 0) {
-               ret = idr_find(&mtd_idr, num);
+               ret = xa_load(&mtd_devs, num);
                if (mtd && mtd != ret)
                        ret = NULL;
        }
@@ -1933,7 +1930,6 @@ static void __exit cleanup_mtd(void)
                remove_proc_entry("mtd", NULL);
        class_unregister(&mtd_class);
        bdi_put(mtd_bdi);
-       idr_destroy(&mtd_idr);
 }
 
 module_init(init_mtd);
index b31c868019adada77b86e028974203f09251739e..978f91daecb393a87c5d7943789d96a963520e69 100644 (file)
@@ -6,7 +6,7 @@
 
 extern struct mutex mtd_table_mutex;
 
-struct mtd_info *__mtd_next_device(int i);
+struct mtd_info *__mtd_next_device(unsigned long i);
 int __must_check add_mtd_device(struct mtd_info *mtd);
 int del_mtd_device(struct mtd_info *mtd);
 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);