diff options
author | Tejun Heo <tj@kernel.org> | 2013-02-07 12:31:34 +1100 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2013-02-14 15:26:19 +1100 |
commit | ba6d6ea640d8f058641398ac42efdcc49ea1f86d (patch) | |
tree | 2ea0c4ccf89b8ecfc87e003703836e337882ef72 /block/genhd.c | |
parent | 303c621883352bc37b1b442f7281c93889717e9e (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>
Diffstat (limited to 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/block/genhd.c b/block/genhd.c index d4e7370c425c..a1ed52af5290 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -411,7 +411,7 @@ static int blk_mangle_minor(int minor) int blk_alloc_devt(struct hd_struct *part, dev_t *devt) { struct gendisk *disk = part_to_disk(part); - int idx, rc; + int idx; /* in consecutive minor range? */ if (part->partno < disk->minors) { @@ -420,20 +420,11 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt) } /* allocate ext devt */ - do { - if (!idr_pre_get(&ext_devt_idr, GFP_KERNEL)) - return -ENOMEM; - mutex_lock(&ext_devt_mutex); - rc = idr_get_new(&ext_devt_idr, part, &idx); - if (!rc && idx >= NR_EXT_DEVT) { - idr_remove(&ext_devt_idr, idx); - rc = -EBUSY; - } - mutex_unlock(&ext_devt_mutex); - } while (rc == -EAGAIN); - - if (rc) - return rc; + mutex_lock(&ext_devt_mutex); + idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_KERNEL); + mutex_unlock(&ext_devt_mutex); + if (idx < 0) + return idx == -ENOSPC ? -EBUSY : idx; *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); return 0; |