path: root/block
diff options
authorLinus Torvalds <>2008-06-09 10:06:24 -0700
committerLinus Torvalds <>2008-06-09 10:06:24 -0700
commitd5791d13b1d45542895104edf4b09476d5ad24b0 (patch)
tree3e3557240717a100dcb63316b4d0c1697e943320 /block
parentf751aa125d1843ea4a9a264b451fd5b1639fab20 (diff)
Fix invalid access errors in blk_lookup_devt
Commit 30f2f0eb4bd2c43d10a8b0d872c6e5ad8f31c9a0 ("block: do_mounts - accept root=<non-existant partition>") extended blk_lookup_devt() to be able to look up partitions that had not yet been registered, but in the process made the assumption that the '&block_class.devices' list only contains disk devices and that you can do 'dev_to_disk(dev)' on them. That isn't actually true. The block_class device list also contains the partitions we've discovered so far, and you can't just do a 'dev_to_disk()' on those. So make sure to only work on devices that block/genhd.c has registered itself, something we can test by checking the 'dev->type' member. This makes the loop in blk_lookup_devt() match the other such loops in this file. [ We may want to do an alternate version that knows to handle _either_ whole-disk devices or partitions, but for now this is the minimal fix for a series of crashes reported by Mariusz Kozlowski in and Ingo in ] Reported-by: Mariusz Kozlowski <> Reported-by: Ingo Molnar <> Cc: Neil Brown <> Cc: Joao Luis Meloni Assirati <> Acked-by: Kay Sievers <> Cc: Greg Kroah-Hartman <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'block')
1 files changed, 2 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 129ad939f9d..b922d4801c8 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -660,6 +660,8 @@ dev_t blk_lookup_devt(const char *name, int part)
list_for_each_entry(dev, &block_class.devices, node) {
+ if (dev->type != &disk_type)
+ continue;
if (strcmp(dev->bus_id, name) == 0) {
struct gendisk *disk = dev_to_disk(dev);