Commit bab998d6 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

block: convert to idr_alloc()

Convert to the much saner new idr interface.  Both bsg and genhd
protect idr w/ mutex making preloading unnecessary.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ce23bba8
...@@ -997,7 +997,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent, ...@@ -997,7 +997,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
{ {
struct bsg_class_device *bcd; struct bsg_class_device *bcd;
dev_t dev; dev_t dev;
int ret, minor; int ret;
struct device *class_dev = NULL; struct device *class_dev = NULL;
const char *devname; const char *devname;
...@@ -1017,23 +1017,16 @@ int bsg_register_queue(struct request_queue *q, struct device *parent, ...@@ -1017,23 +1017,16 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
mutex_lock(&bsg_mutex); mutex_lock(&bsg_mutex);
ret = idr_pre_get(&bsg_minor_idr, GFP_KERNEL); ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL);
if (!ret) { if (ret < 0) {
ret = -ENOMEM; if (ret == -ENOSPC) {
goto unlock;
}
ret = idr_get_new(&bsg_minor_idr, bcd, &minor);
if (ret < 0)
goto unlock;
if (minor >= BSG_MAX_DEVS) {
printk(KERN_ERR "bsg: too many bsg devices\n"); printk(KERN_ERR "bsg: too many bsg devices\n");
ret = -EINVAL; ret = -EINVAL;
goto remove_idr; }
goto unlock;
} }
bcd->minor = minor; bcd->minor = ret;
bcd->queue = q; bcd->queue = q;
bcd->parent = get_device(parent); bcd->parent = get_device(parent);
bcd->release = release; bcd->release = release;
...@@ -1059,8 +1052,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent, ...@@ -1059,8 +1052,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
device_unregister(class_dev); device_unregister(class_dev);
put_dev: put_dev:
put_device(parent); put_device(parent);
remove_idr: idr_remove(&bsg_minor_idr, bcd->minor);
idr_remove(&bsg_minor_idr, minor);
unlock: unlock:
mutex_unlock(&bsg_mutex); mutex_unlock(&bsg_mutex);
return ret; return ret;
......
...@@ -411,7 +411,7 @@ static int blk_mangle_minor(int minor) ...@@ -411,7 +411,7 @@ static int blk_mangle_minor(int minor)
int blk_alloc_devt(struct hd_struct *part, dev_t *devt) int blk_alloc_devt(struct hd_struct *part, dev_t *devt)
{ {
struct gendisk *disk = part_to_disk(part); struct gendisk *disk = part_to_disk(part);
int idx, rc; int idx;
/* in consecutive minor range? */ /* in consecutive minor range? */
if (part->partno < disk->minors) { if (part->partno < disk->minors) {
...@@ -420,20 +420,11 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt) ...@@ -420,20 +420,11 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt)
} }
/* allocate ext devt */ /* allocate ext devt */
do {
if (!idr_pre_get(&ext_devt_idr, GFP_KERNEL))
return -ENOMEM;
mutex_lock(&ext_devt_mutex); mutex_lock(&ext_devt_mutex);
rc = idr_get_new(&ext_devt_idr, part, &idx); idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_KERNEL);
if (!rc && idx >= NR_EXT_DEVT) {
idr_remove(&ext_devt_idr, idx);
rc = -EBUSY;
}
mutex_unlock(&ext_devt_mutex); mutex_unlock(&ext_devt_mutex);
} while (rc == -EAGAIN); if (idx < 0)
return idx == -ENOSPC ? -EBUSY : idx;
if (rc)
return rc;
*devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx));
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment