Skip to contentSkip to conversation

Make a basic error check for failure in register_disk()

PATCH New Zdenek Kabelac 1 participant 1 message Sep 22, 2009 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make a basic error check for failure in register_disk()

Make a basic error check for failure in register_disk() to avoid kernel BUG when sysfs entry could not be created (i.e. duplicate filename). Fix is not perfect as register_disk() and add_disk() should probably return error code in this case but avoids this BUG message:

kernel BUG at fs/sysfs/group.c:65!
[<ffffffff812d6eac>] ? device_add+0x3c/0x5a0

 [<ffffffff811767c3>] sysfs_create_group+0x13/0x20
 [<ffffffff810c6c14>] blk_trace_init_sysfs+0x14/0x20
 [<ffffffff8121e3b0>] blk_register_queue+0x40/0x100
 [<ffffffff81223438>] add_disk+0xf8/0x170
 [<ffffffffa00bb3aa>] dm_create+0x37a/0x5b0 [dm_mod]
 ...

Problem has been noticed during check of some dm error code path.

---
 block/genhd.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
block/genhd.c +4 -0
index f4c64c2..317f961 100644
@@ -544,6 +544,10 @@ void add_disk(struct gendisk *disk)
 	blk_register_region(disk_devt(disk), disk->minors, NULL,
 			    exact_match, exact_lock, disk);
 	register_disk(disk);
+	if (!disk_to_dev(disk)->kobj.parent) {
+		WARN_ON(1);
+		return;
+	}
 	blk_register_queue(disk);
 
 	bdi = &disk->queue->backing_dev_info;