summaryrefslogtreecommitdiff
path: root/block/bsg.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 17:03:57 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 19:10:15 -0800
commitbab998d62f12db12b3ddf1e06b2ecd4ed9e7ae45 (patch)
tree4fdd87842d72efb147ce12e513ccaccabebae4fb /block/bsg.c
parentce23bba842aee98092225d9576dba47c82352521 (diff)
downloadlwn-bab998d62f12db12b3ddf1e06b2ecd4ed9e7ae45.tar.gz
lwn-bab998d62f12db12b3ddf1e06b2ecd4ed9e7ae45.zip
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: Tejun Heo <tj@kernel.org> Acked-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'block/bsg.c')
-rw-r--r--block/bsg.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/block/bsg.c b/block/bsg.c
index ff64ae3bacee..3ca92ebf6bbb 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -997,7 +997,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
{
struct bsg_class_device *bcd;
dev_t dev;
- int ret, minor;
+ int ret;
struct device *class_dev = NULL;
const char *devname;
@@ -1017,23 +1017,16 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
mutex_lock(&bsg_mutex);
- ret = idr_pre_get(&bsg_minor_idr, GFP_KERNEL);
- if (!ret) {
- ret = -ENOMEM;
- goto unlock;
- }
-
- ret = idr_get_new(&bsg_minor_idr, bcd, &minor);
- if (ret < 0)
+ ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL);
+ if (ret < 0) {
+ if (ret == -ENOSPC) {
+ printk(KERN_ERR "bsg: too many bsg devices\n");
+ ret = -EINVAL;
+ }
goto unlock;
-
- if (minor >= BSG_MAX_DEVS) {
- printk(KERN_ERR "bsg: too many bsg devices\n");
- ret = -EINVAL;
- goto remove_idr;
}
- bcd->minor = minor;
+ bcd->minor = ret;
bcd->queue = q;
bcd->parent = get_device(parent);
bcd->release = release;
@@ -1059,8 +1052,7 @@ unregister_class_dev:
device_unregister(class_dev);
put_dev:
put_device(parent);
-remove_idr:
- idr_remove(&bsg_minor_idr, minor);
+ idr_remove(&bsg_minor_idr, bcd->minor);
unlock:
mutex_unlock(&bsg_mutex);
return ret;