static dev_t ocxl_dev;
static struct class *ocxl_class;
-static struct mutex minors_idr_lock;
-static struct idr minors_idr;
+static DEFINE_XARRAY_ALLOC(ocxl_devs);
static struct ocxl_file_info *find_file_info(dev_t devno)
{
- struct ocxl_file_info *info;
-
/*
* We don't declare an RCU critical section here, as our AFU
* is protected by a reference counter on the device. By the time the
- * info reference is removed from the idr, the ref count of
+ * info reference is removed from the array, the ref count of
* the device is already at 0, so no user API will access that AFU and
* this function can't return it.
*/
- info = idr_find(&minors_idr, MINOR(devno));
- return info;
+ return xa_load(&ocxl_devs, MINOR(devno));
}
static int allocate_minor(struct ocxl_file_info *info)
{
- int minor;
+ int err, minor;
- mutex_lock(&minors_idr_lock);
- minor = idr_alloc(&minors_idr, info, 0, OCXL_NUM_MINORS, GFP_KERNEL);
- mutex_unlock(&minors_idr_lock);
+ err = xa_alloc(&ocxl_devs, &minor, info,
+ XA_LIMIT(0, OCXL_NUM_MINORS - 1), GFP_KERNEL);
+ if (err < 0)
+ return err;
return minor;
}
static void free_minor(struct ocxl_file_info *info)
{
- mutex_lock(&minors_idr_lock);
- idr_remove(&minors_idr, MINOR(info->dev.devt));
- mutex_unlock(&minors_idr_lock);
+ xa_erase(&ocxl_devs, MINOR(info->dev.devt));
}
static int afu_open(struct inode *inode, struct file *file)
{
int rc;
- mutex_init(&minors_idr_lock);
- idr_init(&minors_idr);
-
rc = alloc_chrdev_region(&ocxl_dev, 0, OCXL_NUM_MINORS, "ocxl");
if (rc) {
pr_err("Unable to allocate ocxl major number: %d\n", rc);
{
class_destroy(ocxl_class);
unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS);
- idr_destroy(&minors_idr);
}