aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/genhd.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 10b9ac46c2da..e8c42bfd12be 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -677,24 +677,38 @@ void genhd_media_change_notify(struct gendisk *disk)
677EXPORT_SYMBOL_GPL(genhd_media_change_notify); 677EXPORT_SYMBOL_GPL(genhd_media_change_notify);
678#endif /* 0 */ 678#endif /* 0 */
679 679
680struct find_block {
681 const char *name;
682 int part;
683};
684
685static int match_id(struct device *dev, void *data)
686{
687 struct find_block *find = data;
688
689 if (dev->type != &disk_type)
690 return 0;
691 if (strcmp(dev->bus_id, find->name) == 0) {
692 struct gendisk *disk = dev_to_disk(dev);
693 if (find->part < disk->minors)
694 return 1;
695 }
696 return 0;
697}
698
680dev_t blk_lookup_devt(const char *name, int part) 699dev_t blk_lookup_devt(const char *name, int part)
681{ 700{
682 struct device *dev; 701 struct device *dev;
683 dev_t devt = MKDEV(0, 0); 702 dev_t devt = MKDEV(0, 0);
703 struct find_block find;
684 704
685 mutex_lock(&block_class_lock); 705 mutex_lock(&block_class_lock);
686 list_for_each_entry(dev, &block_class.devices, node) { 706 find.name = name;
687 if (dev->type != &disk_type) 707 find.part = part;
688 continue; 708 dev = class_find_device(&block_class, NULL, (void *)&find, match_id);
689 if (strcmp(dev->bus_id, name) == 0) { 709 if (dev)
690 struct gendisk *disk = dev_to_disk(dev); 710 devt = MKDEV(MAJOR(dev->devt),
691 711 MINOR(dev->devt) + part);
692 if (part < disk->minors)
693 devt = MKDEV(MAJOR(dev->devt),
694 MINOR(dev->devt) + part);
695 break;
696 }
697 }
698 mutex_unlock(&block_class_lock); 712 mutex_unlock(&block_class_lock);
699 713
700 return devt; 714 return devt;