.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);
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
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 */
*/
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);
}
}
- 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)
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;
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;
}
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);
}
}
} else if (num >= 0) {
- ret = idr_find(&mtd_idr, num);
+ ret = xa_load(&mtd_devs, num);
if (mtd && mtd != ret)
ret = NULL;
}
remove_proc_entry("mtd", NULL);
class_unregister(&mtd_class);
bdi_put(mtd_bdi);
- idr_destroy(&mtd_idr);
}
module_init(init_mtd);