From: Matthew Wilcox Date: Mon, 18 Feb 2019 20:20:22 +0000 (-0500) Subject: ocxl: Convert minors_idr to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=35fda36a0cab840e033b3c15ca03cdf3e2ca840c;p=users%2Fwilly%2Fxarray.git ocxl: Convert minors_idr to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c index 2870c25da166f..1edbb7ddb3e1b 100644 --- a/drivers/misc/ocxl/file.c +++ b/drivers/misc/ocxl/file.c @@ -15,39 +15,34 @@ 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) @@ -589,9 +584,6 @@ int ocxl_file_init(void) { 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); @@ -613,5 +605,4 @@ void ocxl_file_exit(void) { class_destroy(ocxl_class); unregister_chrdev_region(ocxl_dev, OCXL_NUM_MINORS); - idr_destroy(&minors_idr); }