md: extend disks_mutex coverage
authorChristoph Hellwig <hch@lst.de>
Wed, 1 Sep 2021 11:38:32 +0000 (13:38 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 20:50:21 +0000 (14:50 -0600)
disks_mutex is intended to serialize md_alloc.  Extended it to also cover
the kobject_uevent call and getting the sysfs dirent to help reducing
error handling complexity.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/md.c

index e04a23d..946bbed 100644 (file)
@@ -5725,12 +5725,12 @@ static int md_alloc(dev_t dev, char *name)
                error = 0;
        }
  abort:
-       mutex_unlock(&disks_mutex);
        if (!error && mddev->kobj.sd) {
                kobject_uevent(&mddev->kobj, KOBJ_ADD);
                mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state");
                mddev->sysfs_level = sysfs_get_dirent_safe(mddev->kobj.sd, "level");
        }
+       mutex_unlock(&disks_mutex);
        mddev_put(mddev);
        return error;
 }