block/loop: convert to idr_alloc()
authorTejun Heo <tj@kernel.org>
Thu, 28 Feb 2013 01:03:58 +0000 (17:03 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Feb 2013 03:10:15 +0000 (19:10 -0800)
Convert to the much saner new idr interface.

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>
drivers/block/loop.c

index c674e5492ec4295e937b2c44af02fa43db99a179..f47dccbda1d44ad799fc68d283c576684335d37d 100644 (file)
@@ -1624,30 +1624,17 @@ static int loop_add(struct loop_device **l, int i)
        if (!lo)
                goto out;
 
        if (!lo)
                goto out;
 
-       if (!idr_pre_get(&loop_index_idr, GFP_KERNEL))
-               goto out_free_dev;
-
+       /* allocate id, if @id >= 0, we're requesting that specific id */
        if (i >= 0) {
        if (i >= 0) {
-               int m;
-
-               /* create specific i in the index */
-               err = idr_get_new_above(&loop_index_idr, lo, i, &m);
-               if (err >= 0 && i != m) {
-                       idr_remove(&loop_index_idr, m);
+               err = idr_alloc(&loop_index_idr, lo, i, i + 1, GFP_KERNEL);
+               if (err == -ENOSPC)
                        err = -EEXIST;
                        err = -EEXIST;
-               }
-       } else if (i == -1) {
-               int m;
-
-               /* get next free nr */
-               err = idr_get_new(&loop_index_idr, lo, &m);
-               if (err >= 0)
-                       i = m;
        } else {
        } else {
-               err = -EINVAL;
+               err = idr_alloc(&loop_index_idr, lo, 0, 0, GFP_KERNEL);
        }
        if (err < 0)
                goto out_free_dev;
        }
        if (err < 0)
                goto out_free_dev;
+       i = err;
 
        lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
        if (!lo->lo_queue)
 
        lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
        if (!lo->lo_queue)