diff options
author | Tejun Heo <tj@kernel.org> | 2013-02-27 20:03:57 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:15 -0500 |
commit | bab998d62f12db12b3ddf1e06b2ecd4ed9e7ae45 (patch) | |
tree | 4fdd87842d72efb147ce12e513ccaccabebae4fb /block/bsg.c | |
parent | ce23bba842aee98092225d9576dba47c82352521 (diff) |
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.c | 26 |
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, | |||
997 | { | 997 | { |
998 | struct bsg_class_device *bcd; | 998 | struct bsg_class_device *bcd; |
999 | dev_t dev; | 999 | dev_t dev; |
1000 | int ret, minor; | 1000 | int ret; |
1001 | struct device *class_dev = NULL; | 1001 | struct device *class_dev = NULL; |
1002 | const char *devname; | 1002 | const char *devname; |
1003 | 1003 | ||
@@ -1017,23 +1017,16 @@ int bsg_register_queue(struct request_queue *q, struct device *parent, | |||
1017 | 1017 | ||
1018 | mutex_lock(&bsg_mutex); | 1018 | mutex_lock(&bsg_mutex); |
1019 | 1019 | ||
1020 | ret = idr_pre_get(&bsg_minor_idr, GFP_KERNEL); | 1020 | ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL); |
1021 | if (!ret) { | 1021 | if (ret < 0) { |
1022 | ret = -ENOMEM; | 1022 | if (ret == -ENOSPC) { |
1023 | goto unlock; | 1023 | printk(KERN_ERR "bsg: too many bsg devices\n"); |
1024 | } | 1024 | ret = -EINVAL; |
1025 | 1025 | } | |
1026 | ret = idr_get_new(&bsg_minor_idr, bcd, &minor); | ||
1027 | if (ret < 0) | ||
1028 | goto unlock; | 1026 | goto unlock; |
1029 | |||
1030 | if (minor >= BSG_MAX_DEVS) { | ||
1031 | printk(KERN_ERR "bsg: too many bsg devices\n"); | ||
1032 | ret = -EINVAL; | ||
1033 | goto remove_idr; | ||
1034 | } | 1027 | } |
1035 | 1028 | ||
1036 | bcd->minor = minor; | 1029 | bcd->minor = ret; |
1037 | bcd->queue = q; | 1030 | bcd->queue = q; |
1038 | bcd->parent = get_device(parent); | 1031 | bcd->parent = get_device(parent); |
1039 | bcd->release = release; | 1032 | bcd->release = release; |
@@ -1059,8 +1052,7 @@ unregister_class_dev: | |||
1059 | device_unregister(class_dev); | 1052 | device_unregister(class_dev); |
1060 | put_dev: | 1053 | put_dev: |
1061 | put_device(parent); | 1054 | put_device(parent); |
1062 | remove_idr: | 1055 | idr_remove(&bsg_minor_idr, bcd->minor); |
1063 | idr_remove(&bsg_minor_idr, minor); | ||
1064 | unlock: | 1056 | unlock: |
1065 | mutex_unlock(&bsg_mutex); | 1057 | mutex_unlock(&bsg_mutex); |
1066 | return ret; | 1058 | return ret; |