add_disk() does not return an error status, but it can
still fail if there are problems elsewhere.

In particular a recent problem caused bdi_register_dev()
to sometimes fail because the name was already in use.

In that case bdi->dev is NULL, so

        retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
                                   "bdi");

triggers an oops, after having already produced warnings.

This patch causes add_disk() to WARN and return if
bdi_register_dev() fails, much like it already does if
blk_alloc_devt() fails.

This should make no difference on a correctly functioning system, but
can make a developers life a bit easier.

Signed-off-by: NeilBrown <ne...@suse.de>

diff --git a/block/genhd.c b/block/genhd.c
index 0a536dc05f3b..e351fc521053 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -612,6 +612,10 @@ void add_disk(struct gendisk *disk)
        /* Register BDI before referencing it from bdev */
        bdi = &disk->queue->backing_dev_info;
        bdi_register_dev(bdi, disk_devt(disk));
+       if (!bdi->dev) {
+               WARN_ON(1);
+               return;
+       }
 
        blk_register_region(disk_devt(disk), disk->minors, NULL,
                            exact_match, exact_lock, disk);

Attachment: pgpDN8swpNffB.pgp
Description: OpenPGP digital signature

Reply via email to