]> git.karo-electronics.de Git - linux-beck.git/commitdiff
[SCSI] sd: Reshuffle init_sd to avoid crash
authorJoel D. Diaz <joeldiaz@us.ibm.com>
Wed, 10 Oct 2012 08:36:11 +0000 (10:36 +0200)
committerJames Bottomley <JBottomley@Parallels.com>
Tue, 27 Nov 2012 04:59:34 +0000 (08:59 +0400)
scsi_register_driver will register a prep_fn() function, which
in turn migh need to use the sd_cdp_pool for DIF.
Which hasn't been initialised at this point, leading to
a crash. So reshuffle the init_sd() and exit_sd() paths
to have the driver registered last.

Signed-off-by: Joel D. Diaz <joeldiaz@us.ibm.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/sd.c

index 352bc77b7c886fb80c057019c3edc2d5b95b7d7e..a45e12ac7e28511e9ed8ed4eae1e05834db30f68 100644 (file)
@@ -3116,10 +3116,6 @@ static int __init init_sd(void)
        if (err)
                goto err_out;
 
-       err = scsi_register_driver(&sd_template.gendrv);
-       if (err)
-               goto err_out_class;
-
        sd_cdb_cache = kmem_cache_create("sd_ext_cdb", SD_EXT_CDB_SIZE,
                                         0, 0, NULL);
        if (!sd_cdb_cache) {
@@ -3133,8 +3129,15 @@ static int __init init_sd(void)
                goto err_out_cache;
        }
 
+       err = scsi_register_driver(&sd_template.gendrv);
+       if (err)
+               goto err_out_driver;
+
        return 0;
 
+err_out_driver:
+       mempool_destroy(sd_cdb_pool);
+
 err_out_cache:
        kmem_cache_destroy(sd_cdb_cache);
 
@@ -3157,10 +3160,10 @@ static void __exit exit_sd(void)
 
        SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n"));
 
+       scsi_unregister_driver(&sd_template.gendrv);
        mempool_destroy(sd_cdb_pool);
        kmem_cache_destroy(sd_cdb_cache);
 
-       scsi_unregister_driver(&sd_template.gendrv);
        class_unregister(&sd_disk_class);
 
        for (i = 0; i < SD_MAJORS; i++)