Skip to content

Commit bab998d

Browse files
htejuntorvalds
authored andcommitted
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>
1 parent ce23bba commit bab998d

2 files changed

Lines changed: 15 additions & 32 deletions

File tree

‎block/bsg.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
997997
{
998998
struct bsg_class_device *bcd;
999999
dev_t dev;
1000-
int ret, minor;
1000+
int ret;
10011001
struct device *class_dev = NULL;
10021002
const char *devname;
10031003

@@ -1017,23 +1017,16 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
10171017

10181018
mutex_lock(&bsg_mutex);
10191019

1020-
ret = idr_pre_get(&bsg_minor_idr, GFP_KERNEL);
1021-
if (!ret) {
1022-
ret = -ENOMEM;
1023-
goto unlock;
1024-
}
1025-
1026-
ret = idr_get_new(&bsg_minor_idr, bcd, &minor);
1027-
if (ret < 0)
1020+
ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL);
1021+
if (ret < 0) {
1022+
if (ret == -ENOSPC) {
1023+
printk(KERN_ERR "bsg: too many bsg devices\n");
1024+
ret = -EINVAL;
1025+
}
10281026
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;
10341027
}
10351028

1036-
bcd->minor = minor;
1029+
bcd->minor = ret;
10371030
bcd->queue = q;
10381031
bcd->parent = get_device(parent);
10391032
bcd->release = release;
@@ -1059,8 +1052,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
10591052
device_unregister(class_dev);
10601053
put_dev:
10611054
put_device(parent);
1062-
remove_idr:
1063-
idr_remove(&bsg_minor_idr, minor);
1055+
idr_remove(&bsg_minor_idr, bcd->minor);
10641056
unlock:
10651057
mutex_unlock(&bsg_mutex);
10661058
return ret;

‎block/genhd.c‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static int blk_mangle_minor(int minor)
411411
int blk_alloc_devt(struct hd_struct *part, dev_t *devt)
412412
{
413413
struct gendisk *disk = part_to_disk(part);
414-
int idx, rc;
414+
int idx;
415415

416416
/* in consecutive minor range? */
417417
if (part->partno < disk->minors) {
@@ -420,20 +420,11 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt)
420420
}
421421

422422
/* allocate ext devt */
423-
do {
424-
if (!idr_pre_get(&ext_devt_idr, GFP_KERNEL))
425-
return -ENOMEM;
426-
mutex_lock(&ext_devt_mutex);
427-
rc = idr_get_new(&ext_devt_idr, part, &idx);
428-
if (!rc && idx >= NR_EXT_DEVT) {
429-
idr_remove(&ext_devt_idr, idx);
430-
rc = -EBUSY;
431-
}
432-
mutex_unlock(&ext_devt_mutex);
433-
} while (rc == -EAGAIN);
434-
435-
if (rc)
436-
return rc;
423+
mutex_lock(&ext_devt_mutex);
424+
idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_KERNEL);
425+
mutex_unlock(&ext_devt_mutex);
426+
if (idx < 0)
427+
return idx == -ENOSPC ? -EBUSY : idx;
437428

438429
*devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx));
439430
return 0;

0 commit comments

Comments
 (0)