diff mbox series

[07/14] bsg: Convert bsg_minor_idr to XArray

Message ID 20190318194821.3470-8-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert block layer & drivers to XArray | expand

Commit Message

Matthew Wilcox March 18, 2019, 7:48 p.m. UTC
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 block/bsg.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/block/bsg.c b/block/bsg.c
index f306853c6b08..e24420a21383 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -16,9 +16,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>
@@ -46,7 +46,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];
@@ -294,7 +294,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);
@@ -401,7 +401,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);
@@ -429,23 +429,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;
 
@@ -460,8 +460,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;