]> www.infradead.org Git - users/willy/xarray.git/commitdiff
bsg: Convert bsg_minor_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Fri, 15 Feb 2019 20:41:46 +0000 (15:41 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 02:35:37 +0000 (22:35 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
block/bsg.c

index 833c44b3d458ea642f95f45f730fd7bb3f27f565..277c5e34ae16d82dddf8377c676fca77044678df 100644 (file)
@@ -9,9 +9,9 @@
 #include <linux/cdev.h>
 #include <linux/jiffies.h>
 #include <linux/percpu.h>
-#include <linux/idr.h>
 #include <linux/bsg.h>
 #include <linux/slab.h>
+#include <linux/xarray.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_ioctl.h>
@@ -39,7 +39,7 @@ struct bsg_device {
 #define BSG_MAX_DEVS           32768
 
 static DEFINE_MUTEX(bsg_mutex);
-static DEFINE_IDR(bsg_minor_idr);
+static DEFINE_XARRAY_ALLOC(bsg_classes);
 
 #define BSG_LIST_ARRAY_SIZE    8
 static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
@@ -287,7 +287,7 @@ static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
         * find the class device
         */
        mutex_lock(&bsg_mutex);
-       bcd = idr_find(&bsg_minor_idr, iminor(inode));
+       bcd = xa_load(&bsg_classes, iminor(inode));
 
        if (!bcd) {
                bd = ERR_PTR(-ENODEV);
@@ -394,7 +394,7 @@ void bsg_unregister_queue(struct request_queue *q)
                return;
 
        mutex_lock(&bsg_mutex);
-       idr_remove(&bsg_minor_idr, bcd->minor);
+       xa_erase(&bsg_classes, bcd->minor);
        if (q->kobj.sd)
                sysfs_remove_link(&q->kobj, "bsg");
        device_unregister(bcd->class_dev);
@@ -422,23 +422,23 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
 
        mutex_lock(&bsg_mutex);
 
-       ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL);
+       ret = xa_alloc(&bsg_classes, &bcd->minor, bcd,
+                       XA_LIMIT(0, BSG_MAX_DEVS - 1), GFP_KERNEL);
        if (ret < 0) {
-               if (ret == -ENOSPC) {
+               if (ret == -EBUSY) {
                        printk(KERN_ERR "bsg: too many bsg devices\n");
                        ret = -EINVAL;
                }
                goto unlock;
        }
 
-       bcd->minor = ret;
        bcd->queue = q;
        bcd->ops = ops;
        dev = MKDEV(bsg_major, bcd->minor);
        class_dev = device_create(bsg_class, parent, dev, NULL, "%s", name);
        if (IS_ERR(class_dev)) {
                ret = PTR_ERR(class_dev);
-               goto idr_remove;
+               goto remove;
        }
        bcd->class_dev = class_dev;
 
@@ -453,8 +453,8 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
 
 unregister_class_dev:
        device_unregister(class_dev);
-idr_remove:
-       idr_remove(&bsg_minor_idr, bcd->minor);
+remove:
+       xa_erase(&bsg_classes, bcd->minor);
 unlock:
        mutex_unlock(&bsg_mutex);
        return ret;