]> www.infradead.org Git - users/willy/xarray.git/commitdiff
ocxl: Convert minors_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 20:20:22 +0000 (15:20 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:11 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/misc/ocxl/file.c

index 2870c25da166f7bc1576464f248940b8396d2699..1edbb7ddb3e1b1009716b87da0fb3487f91a6921 100644 (file)
 
 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);
 }