lightnvm: prematurely activate nvm_dev
authorMatias Bjørling <m@bjorling.me>
Mon, 16 Nov 2015 14:34:42 +0000 (15:34 +0100)
committerJens Axboe <axboe@fb.com>
Mon, 16 Nov 2015 22:20:31 +0000 (15:20 -0700)
We register with nvm_devices when there registration can still fail.
Move the final registration at the end of the nvm_register function
to make sure we are fully registered when added to the nvm_devices list.

Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/core.c

index 0985a032debc6abbd98c0119e2c4b172ba00b266..40e6cfae4585d6abd60c82371b8454c82ac4ba5b 100644 (file)
@@ -318,10 +318,6 @@ int nvm_register(struct request_queue *q, char *disk_name,
        if (ret)
                goto err_init;
 
-       down_write(&nvm_lock);
-       list_add(&dev->devices, &nvm_devices);
-       up_write(&nvm_lock);
-
        if (dev->ops->max_phys_sect > 1) {
                dev->ppalist_pool = dev->ops->create_dma_pool(dev->q,
                                                                "ppalist");
@@ -334,6 +330,10 @@ int nvm_register(struct request_queue *q, char *disk_name,
                return -EINVAL;
        }
 
+       down_write(&nvm_lock);
+       list_add(&dev->devices, &nvm_devices);
+       up_write(&nvm_lock);
+
        return 0;
 err_init:
        kfree(dev);