skd: register block device only if some devices are present
authorBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Tue, 5 Nov 2013 11:37:02 +0000 (12:37 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 8 Nov 2013 16:10:30 +0000 (09:10 -0700)
Register block device in skd_pci_probe() instead of in skd_init() so it
is registered only if some devices are present (currently it is always
registered when the driver is loaded). Please note that this change
depends on the fact that register_blkdev(0, ...) never returns 0.

Cc: Akhil Bhansali <abhansali@stec-inc.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/skd_main.c

index 99d5d1251c45fb8f3e0c58e812e0d3fb07f1ca02..9ff34be89f99c56dbf6e372d212e6829a77564de 100644 (file)
@@ -4899,6 +4899,14 @@ static int skd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                }
        }
 
+       if (!skd_major) {
+               rc = register_blkdev(0, DRV_NAME);
+               if (rc < 0)
+                       goto err_out_regions;
+               BUG_ON(!rc);
+               skd_major = rc;
+       }
+
        skdev = skd_construct(pdev);
        if (skdev == NULL) {
                rc = -ENOMEM;
@@ -5396,8 +5404,6 @@ static void skd_log_skreq(struct skd_device *skdev,
 
 static int __init skd_init(void)
 {
-       int rc = -ENOMEM;
-
        pr_info(PFX " v%s-b%s loaded\n", DRV_VERSION, DRV_BUILD_ID);
 
        switch (skd_isr_type) {
@@ -5448,24 +5454,7 @@ static int __init skd_init(void)
                skd_max_pass_thru = SKD_N_SPECIAL_CONTEXT;
        }
 
-       /* Obtain major device number. */
-       rc = register_blkdev(0, DRV_NAME);
-       if (rc < 0)
-               goto err_register_blkdev;
-
-       skd_major = rc;
-
-       rc = pci_register_driver(&skd_driver);
-       if (rc < 0)
-               goto err_pci_register_driver;
-
-       return rc;
-
-err_pci_register_driver:
-       unregister_blkdev(skd_major, DRV_NAME);
-
-err_register_blkdev:
-       return rc;
+       return pci_register_driver(&skd_driver);
 }
 
 static void __exit skd_exit(void)
@@ -5473,7 +5462,9 @@ static void __exit skd_exit(void)
        pr_info(PFX " v%s-b%s unloading\n", DRV_VERSION, DRV_BUILD_ID);
 
        pci_unregister_driver(&skd_driver);
-       unregister_blkdev(skd_major, DRV_NAME);
+
+       if (skd_major)
+               unregister_blkdev(skd_major, DRV_NAME);
 }
 
 module_init(skd_init);