diff options
Diffstat (limited to 'block')
-rw-r--r-- | block/genhd.c | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/block/genhd.c b/block/genhd.c index 65b7386c26d8..36b9f1bdd91f 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -537,22 +537,15 @@ struct gendisk *get_gendisk(dev_t devt, int *partno) | |||
537 | */ | 537 | */ |
538 | extern struct block_device *bdget_disk(struct gendisk *disk, int partno) | 538 | extern struct block_device *bdget_disk(struct gendisk *disk, int partno) |
539 | { | 539 | { |
540 | dev_t devt = MKDEV(0, 0); | 540 | struct hd_struct *part; |
541 | struct block_device *bdev = NULL; | ||
541 | 542 | ||
542 | if (partno == 0) | 543 | part = disk_get_part(disk, partno); |
543 | devt = disk_devt(disk); | 544 | if (part && (part->nr_sects || partno == 0)) |
544 | else { | 545 | bdev = bdget(part_devt(part)); |
545 | struct hd_struct *part; | 546 | disk_put_part(part); |
546 | 547 | ||
547 | part = disk_get_part(disk, partno); | 548 | return bdev; |
548 | if (part && part->nr_sects) | ||
549 | devt = part_devt(part); | ||
550 | disk_put_part(part); | ||
551 | } | ||
552 | |||
553 | if (likely(devt != MKDEV(0, 0))) | ||
554 | return bdget(devt); | ||
555 | return NULL; | ||
556 | } | 549 | } |
557 | EXPORT_SYMBOL(bdget_disk); | 550 | EXPORT_SYMBOL(bdget_disk); |
558 | 551 | ||
@@ -1000,27 +993,18 @@ dev_t blk_lookup_devt(const char *name, int partno) | |||
1000 | class_dev_iter_init(&iter, &block_class, NULL, &disk_type); | 993 | class_dev_iter_init(&iter, &block_class, NULL, &disk_type); |
1001 | while ((dev = class_dev_iter_next(&iter))) { | 994 | while ((dev = class_dev_iter_next(&iter))) { |
1002 | struct gendisk *disk = dev_to_disk(dev); | 995 | struct gendisk *disk = dev_to_disk(dev); |
996 | struct hd_struct *part; | ||
1003 | 997 | ||
1004 | if (strcmp(dev->bus_id, name)) | 998 | if (strcmp(dev->bus_id, name)) |
1005 | continue; | 999 | continue; |
1006 | if (partno < 0 || partno >= disk_max_parts(disk)) | ||
1007 | continue; | ||
1008 | |||
1009 | if (partno == 0) | ||
1010 | devt = disk_devt(disk); | ||
1011 | else { | ||
1012 | struct hd_struct *part; | ||
1013 | |||
1014 | part = disk_get_part(disk, partno); | ||
1015 | if (!part || !part->nr_sects) { | ||
1016 | disk_put_part(part); | ||
1017 | continue; | ||
1018 | } | ||
1019 | 1000 | ||
1001 | part = disk_get_part(disk, partno); | ||
1002 | if (part && (part->nr_sects || partno == 0)) { | ||
1020 | devt = part_devt(part); | 1003 | devt = part_devt(part); |
1021 | disk_put_part(part); | 1004 | disk_put_part(part); |
1005 | break; | ||
1022 | } | 1006 | } |
1023 | break; | 1007 | disk_put_part(part); |
1024 | } | 1008 | } |
1025 | class_dev_iter_exit(&iter); | 1009 | class_dev_iter_exit(&iter); |
1026 | return devt; | 1010 | return devt; |