From: Matthew Wilcox Date: Mon, 18 Feb 2019 20:27:48 +0000 (-0500) Subject: mtdcore: Convert mtd_idr to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=16f99b09225b6f6f681cf199d5a781b437f7eeb5;p=users%2Fwilly%2Fxarray.git mtdcore: Convert mtd_idr to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 408615f29e57..4508c88926a7 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -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); diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h index b31c868019ad..978f91daecb3 100644 --- a/drivers/mtd/mtdcore.h +++ b/drivers/mtd/mtdcore.h @@ -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);