usb: storage: fix module reference for scsi host
authorAkinobu Mita <akinobu.mita@gmail.com>
Wed, 6 May 2015 09:24:21 +0000 (18:24 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 10 May 2015 14:03:50 +0000 (16:03 +0200)
While accessing a unusual usb storage (ums-alauda, ums-cypress, ...),
the module reference count is not incremented.  Because these drivers
allocate scsi hosts with usb_stor_host_template defined in usb-storage
module.  So these drivers always can be unloaded.

This fixes it by preparing scsi host template which is initialized
at module_init() for each ums-* driver.  In order to minimize the
difference in ums-* drivers, introduce module_usb_stor_driver() helper
macro which is same as module_usb_driver() except that it also
initializes scsi host template.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Vinayak Holikatti <vinholikatti@gmail.com>
Cc: Dolev Raviv <draviv@codeaurora.org>
Cc: Sujit Reddy Thumma <sthumma@codeaurora.org>
Cc: Subhash Jadavani <subhashj@codeaurora.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Hannes Reinecke <hare@suse.de>
Cc: linux-usb@vger.kernel.org
Cc: usb-storage@lists.one-eyed-alien.net
Cc: linux-scsi@vger.kernel.org
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 files changed:
drivers/usb/storage/alauda.c
drivers/usb/storage/cypress_atacb.c
drivers/usb/storage/datafab.c
drivers/usb/storage/ene_ub6250.c
drivers/usb/storage/freecom.c
drivers/usb/storage/isd200.c
drivers/usb/storage/jumpshot.c
drivers/usb/storage/karma.c
drivers/usb/storage/onetouch.c
drivers/usb/storage/realtek_cr.c
drivers/usb/storage/scsiglue.c
drivers/usb/storage/scsiglue.h
drivers/usb/storage/sddr09.c
drivers/usb/storage/sddr55.c
drivers/usb/storage/shuttle_usbat.c
drivers/usb/storage/usb.c
drivers/usb/storage/usb.h

index 4b55ab66a5347c44d846ce4ecff5211ac14fb6f5..171fa7d793bc5b5e3dd467b8d4c84dc82a2980df 100644 (file)
@@ -42,6 +42,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-alauda"
 
 MODULE_DESCRIPTION("Driver for Alauda-based card readers");
 MODULE_AUTHOR("Daniel Drake <dsd@gentoo.org>");
@@ -1232,6 +1235,8 @@ static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
        return USB_STOR_TRANSPORT_FAILED;
 }
 
+static struct scsi_host_template alauda_host_template;
+
 static int alauda_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -1239,7 +1244,8 @@ static int alauda_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - alauda_usb_ids) + alauda_unusual_dev_list);
+                       (id - alauda_usb_ids) + alauda_unusual_dev_list,
+                       &alauda_host_template);
        if (result)
                return result;
 
@@ -1253,7 +1259,7 @@ static int alauda_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver alauda_driver = {
-       .name =         "ums-alauda",
+       .name =         DRV_NAME,
        .probe =        alauda_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1266,4 +1272,4 @@ static struct usb_driver alauda_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(alauda_driver);
+module_usb_stor_driver(alauda_driver, alauda_host_template, DRV_NAME);
index b3466d1395f20f7eae934d3bebb1f38b8800c230..c80d3dec9a34fcc39252dbae62f7f98beb191199 100644 (file)
@@ -30,6 +30,8 @@
 #include "scsiglue.h"
 #include "debug.h"
 
+#define DRV_NAME "ums-cypress"
+
 MODULE_DESCRIPTION("SAT support for Cypress USB/ATA bridges with ATACB");
 MODULE_AUTHOR("Matthieu Castet <castet.matthieu@free.fr>");
 MODULE_LICENSE("GPL");
@@ -241,6 +243,7 @@ end:
                srb->cmd_len = 12;
 }
 
+static struct scsi_host_template cypress_host_template;
 
 static int cypress_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
@@ -250,7 +253,8 @@ static int cypress_probe(struct usb_interface *intf,
        struct usb_device *device;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - cypress_usb_ids) + cypress_unusual_dev_list);
+                       (id - cypress_usb_ids) + cypress_unusual_dev_list,
+                       &cypress_host_template);
        if (result)
                return result;
 
@@ -273,7 +277,7 @@ static int cypress_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver cypress_driver = {
-       .name =         "ums-cypress",
+       .name =         DRV_NAME,
        .probe =        cypress_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -286,4 +290,4 @@ static struct usb_driver cypress_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(cypress_driver);
+module_usb_stor_driver(cypress_driver, cypress_host_template, DRV_NAME);
index 7b17c2169812a64be584081ec7a9e960a8845786..aa4f51944a4aaf5992b90dce6408971da9a3a51e 100644 (file)
@@ -59,6 +59,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-datafab"
 
 MODULE_DESCRIPTION("Driver for Datafab USB Compact Flash reader");
 MODULE_AUTHOR("Jimmie Mayfield <mayfield+datafab@sackheads.org>");
@@ -721,6 +724,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
        return USB_STOR_TRANSPORT_FAILED;
 }
 
+static struct scsi_host_template datafab_host_template;
+
 static int datafab_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -728,7 +733,8 @@ static int datafab_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - datafab_usb_ids) + datafab_unusual_dev_list);
+                       (id - datafab_usb_ids) + datafab_unusual_dev_list,
+                       &datafab_host_template);
        if (result)
                return result;
 
@@ -742,7 +748,7 @@ static int datafab_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver datafab_driver = {
-       .name =         "ums-datafab",
+       .name =         DRV_NAME,
        .probe =        datafab_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -755,4 +761,4 @@ static struct usb_driver datafab_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(datafab_driver);
+module_usb_stor_driver(datafab_driver, datafab_host_template, DRV_NAME);
index 56f782bef36b3d8651a1f9f6aae6f244b8eba21b..f3cf4cecd2b7c8d6b570b672c491638a5ed0cb95 100644 (file)
@@ -28,6 +28,7 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
 
 #define SD_INIT1_FIRMWARE "ene-ub6250/sd_init1.bin"
 #define SD_INIT2_FIRMWARE "ene-ub6250/sd_init2.bin"
@@ -36,6 +37,8 @@
 #define MSP_RW_FIRMWARE "ene-ub6250/msp_rdwr.bin"
 #define MS_RW_FIRMWARE "ene-ub6250/ms_rdwr.bin"
 
+#define DRV_NAME "ums_eneub6250"
+
 MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
 MODULE_LICENSE("GPL");
 MODULE_FIRMWARE(SD_INIT1_FIRMWARE);
@@ -2307,6 +2310,7 @@ static int ene_transport(struct scsi_cmnd *srb, struct us_data *us)
        return 0;
 }
 
+static struct scsi_host_template ene_ub6250_host_template;
 
 static int ene_ub6250_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
@@ -2316,7 +2320,8 @@ static int ene_ub6250_probe(struct usb_interface *intf,
        struct us_data *us;
 
        result = usb_stor_probe1(&us, intf, id,
-                  (id - ene_ub6250_usb_ids) + ene_ub6250_unusual_dev_list);
+                  (id - ene_ub6250_usb_ids) + ene_ub6250_unusual_dev_list,
+                  &ene_ub6250_host_template);
        if (result)
                return result;
 
@@ -2404,7 +2409,7 @@ static int ene_ub6250_reset_resume(struct usb_interface *iface)
 #endif
 
 static struct usb_driver ene_ub6250_driver = {
-       .name =         "ums_eneub6250",
+       .name =         DRV_NAME,
        .probe =        ene_ub6250_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -2417,4 +2422,4 @@ static struct usb_driver ene_ub6250_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(ene_ub6250_driver);
+module_usb_stor_driver(ene_ub6250_driver, ene_ub6250_host_template, DRV_NAME);
index ef16068b708704dad1cd2abda3efee0a7754304b..3f2b08966b9dd524d2baff3940914f21f803afa5 100644 (file)
@@ -34,6 +34,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-freecom"
 
 MODULE_DESCRIPTION("Driver for Freecom USB/IDE adaptor");
 MODULE_AUTHOR("David Brown <usb-storage@davidb.org>");
@@ -523,6 +526,8 @@ static void pdump(struct us_data *us, void *ibuffer, int length)
 }
 #endif
 
+static struct scsi_host_template freecom_host_template;
+
 static int freecom_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -530,7 +535,8 @@ static int freecom_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - freecom_usb_ids) + freecom_unusual_dev_list);
+                       (id - freecom_usb_ids) + freecom_unusual_dev_list,
+                       &freecom_host_template);
        if (result)
                return result;
 
@@ -544,7 +550,7 @@ static int freecom_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver freecom_driver = {
-       .name =         "ums-freecom",
+       .name =         DRV_NAME,
        .probe =        freecom_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -557,4 +563,4 @@ static struct usb_driver freecom_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(freecom_driver);
+module_usb_stor_driver(freecom_driver, freecom_host_template, DRV_NAME);
index 076178645ba43fed2e9245c9014a231207524007..1bac215202d20b0783890b28d9dbef886a5af35b 100644 (file)
@@ -60,6 +60,8 @@
 #include "debug.h"
 #include "scsiglue.h"
 
+#define DRV_NAME "ums-isd200"
+
 MODULE_DESCRIPTION("Driver for In-System Design, Inc. ISD200 ASIC");
 MODULE_AUTHOR("Björn Stenberg <bjorn@haxx.se>");
 MODULE_LICENSE("GPL");
@@ -1537,6 +1539,8 @@ static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
        isd200_srb_set_bufflen(srb, orig_bufflen);
 }
 
+static struct scsi_host_template isd200_host_template;
+
 static int isd200_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -1544,7 +1548,8 @@ static int isd200_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - isd200_usb_ids) + isd200_unusual_dev_list);
+                       (id - isd200_usb_ids) + isd200_unusual_dev_list,
+                       &isd200_host_template);
        if (result)
                return result;
 
@@ -1556,7 +1561,7 @@ static int isd200_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver isd200_driver = {
-       .name =         "ums-isd200",
+       .name =         DRV_NAME,
        .probe =        isd200_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1569,4 +1574,4 @@ static struct usb_driver isd200_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(isd200_driver);
+module_usb_stor_driver(isd200_driver, isd200_host_template, DRV_NAME);
index 563078be6547844106e9927540d17e556d1971fc..ee613e258db0e9c17f617971790b0495c9677fc7 100644 (file)
@@ -56,7 +56,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
 
+#define DRV_NAME "ums-jumpshot"
 
 MODULE_DESCRIPTION("Driver for Lexar \"Jumpshot\" Compact Flash reader");
 MODULE_AUTHOR("Jimmie Mayfield <mayfield+usb@sackheads.org>");
@@ -647,6 +649,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
        return USB_STOR_TRANSPORT_FAILED;
 }
 
+static struct scsi_host_template jumpshot_host_template;
+
 static int jumpshot_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -654,7 +658,8 @@ static int jumpshot_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - jumpshot_usb_ids) + jumpshot_unusual_dev_list);
+                       (id - jumpshot_usb_ids) + jumpshot_unusual_dev_list,
+                       &jumpshot_host_template);
        if (result)
                return result;
 
@@ -668,7 +673,7 @@ static int jumpshot_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver jumpshot_driver = {
-       .name =         "ums-jumpshot",
+       .name =         DRV_NAME,
        .probe =        jumpshot_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -681,4 +686,4 @@ static struct usb_driver jumpshot_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(jumpshot_driver);
+module_usb_stor_driver(jumpshot_driver, jumpshot_host_template, DRV_NAME);
index 94d16ee5e84bcaab93afab0cf0b15e088f910c06..ae201e69475c291d8fe5d1887224d49f935f1dde 100644 (file)
@@ -28,6 +28,9 @@
 #include "usb.h"
 #include "transport.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-karma"
 
 MODULE_DESCRIPTION("Driver for Rio Karma");
 MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>, Keith Bennett <keith@mcs.st-and.ac.uk>");
@@ -200,6 +203,8 @@ out:
        return ret;
 }
 
+static struct scsi_host_template karma_host_template;
+
 static int karma_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -207,7 +212,8 @@ static int karma_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - karma_usb_ids) + karma_unusual_dev_list);
+                       (id - karma_usb_ids) + karma_unusual_dev_list,
+                       &karma_host_template);
        if (result)
                return result;
 
@@ -220,7 +226,7 @@ static int karma_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver karma_driver = {
-       .name =         "ums-karma",
+       .name =         DRV_NAME,
        .probe =        karma_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -233,4 +239,4 @@ static struct usb_driver karma_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(karma_driver);
+module_usb_stor_driver(karma_driver, karma_host_template, DRV_NAME);
index 74e2aa23b04501792fb2236b195924bbc1bd5ab1..acc3d03d8c1e08849c30acdad246f6dcdd0cf18e 100644 (file)
@@ -35,6 +35,9 @@
 #include <linux/usb/input.h>
 #include "usb.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-onetouch"
 
 MODULE_DESCRIPTION("Maxtor USB OneTouch hard drive button driver");
 MODULE_AUTHOR("Nick Sillik <n.sillik@temple.edu>");
@@ -283,6 +286,8 @@ static void onetouch_release_input(void *onetouch_)
        }
 }
 
+static struct scsi_host_template onetouch_host_template;
+
 static int onetouch_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -290,7 +295,8 @@ static int onetouch_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - onetouch_usb_ids) + onetouch_unusual_dev_list);
+                       (id - onetouch_usb_ids) + onetouch_unusual_dev_list,
+                       &onetouch_host_template);
        if (result)
                return result;
 
@@ -301,7 +307,7 @@ static int onetouch_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver onetouch_driver = {
-       .name =         "ums-onetouch",
+       .name =         DRV_NAME,
        .probe =        onetouch_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -314,4 +320,4 @@ static struct usb_driver onetouch_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(onetouch_driver);
+module_usb_stor_driver(onetouch_driver, onetouch_host_template, DRV_NAME);
index 27e4a580d2ed2fddb97e543ce5aafbd4f6280032..20433563a6016c8711b344bfe22e58d4a1bda0f0 100644 (file)
@@ -39,6 +39,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-realtek"
 
 MODULE_DESCRIPTION("Driver for Realtek USB Card Reader");
 MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>");
@@ -1034,6 +1037,8 @@ INIT_FAIL:
        return -EIO;
 }
 
+static struct scsi_host_template realtek_cr_host_template;
+
 static int realtek_cr_probe(struct usb_interface *intf,
                            const struct usb_device_id *id)
 {
@@ -1044,7 +1049,8 @@ static int realtek_cr_probe(struct usb_interface *intf,
 
        result = usb_stor_probe1(&us, intf, id,
                                 (id - realtek_cr_ids) +
-                                realtek_cr_unusual_dev_list);
+                                realtek_cr_unusual_dev_list,
+                                &realtek_cr_host_template);
        if (result)
                return result;
 
@@ -1054,7 +1060,7 @@ static int realtek_cr_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver realtek_cr_driver = {
-       .name = "ums-realtek",
+       .name = DRV_NAME,
        .probe = realtek_cr_probe,
        .disconnect = usb_stor_disconnect,
        /* .suspend =      usb_stor_suspend, */
@@ -1070,4 +1076,4 @@ static struct usb_driver realtek_cr_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(realtek_cr_driver);
+module_usb_stor_driver(realtek_cr_driver, realtek_cr_host_template, DRV_NAME);
index a8cbbffe822c894c6be885ca48dddecd49792072..c922d8b64362c8261ec8c966eac8a74579ed4435 100644 (file)
@@ -536,7 +536,7 @@ static struct device_attribute *sysfs_device_attr_list[] = {
  * this defines our host template, with which we'll allocate hosts
  */
 
-struct scsi_host_template usb_stor_host_template = {
+static const struct scsi_host_template usb_stor_host_template = {
        /* basic userland interface stuff */
        .name =                         "usb-storage",
        .proc_name =                    "usb-storage",
@@ -588,6 +588,16 @@ struct scsi_host_template usb_stor_host_template = {
        .module =                       THIS_MODULE
 };
 
+void usb_stor_host_template_init(struct scsi_host_template *sht,
+                                const char *name, struct module *owner)
+{
+       *sht = usb_stor_host_template;
+       sht->name = name;
+       sht->proc_name = name;
+       sht->module = owner;
+}
+EXPORT_SYMBOL_GPL(usb_stor_host_template_init);
+
 /* To Report "Illegal Request: Invalid Field in CDB */
 unsigned char usb_stor_sense_invalidCDB[18] = {
        [0]     = 0x70,                     /* current error */
index ffa1cca93d2cfc2c20bb9c44e57cec9bb0b4bb2b..5494d87607fb671437a20e8b86aefdb7dd4ad835 100644 (file)
@@ -41,8 +41,9 @@
 
 extern void usb_stor_report_device_reset(struct us_data *us);
 extern void usb_stor_report_bus_reset(struct us_data *us);
+extern void usb_stor_host_template_init(struct scsi_host_template *sht,
+                                       const char *name, struct module *owner);
 
 extern unsigned char usb_stor_sense_invalidCDB[18];
-extern struct scsi_host_template usb_stor_host_template;
 
 #endif
index 3847053d732cc6974bcfd6828043c6e79853cb4d..b74603689b9e87f14412b2d20df2b043a47c0453 100644 (file)
@@ -52,6 +52,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-sddr09"
 
 MODULE_DESCRIPTION("Driver for SanDisk SDDR-09 SmartMedia reader");
 MODULE_AUTHOR("Andries Brouwer <aeb@cwi.nl>, Robert Baruch <autophile@starband.net>");
@@ -1738,6 +1741,8 @@ usb_stor_sddr09_init(struct us_data *us) {
        return sddr09_common_init(us);
 }
 
+static struct scsi_host_template sddr09_host_template;
+
 static int sddr09_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -1745,7 +1750,8 @@ static int sddr09_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - sddr09_usb_ids) + sddr09_unusual_dev_list);
+                       (id - sddr09_usb_ids) + sddr09_unusual_dev_list,
+                       &sddr09_host_template);
        if (result)
                return result;
 
@@ -1766,7 +1772,7 @@ static int sddr09_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver sddr09_driver = {
-       .name =         "ums-sddr09",
+       .name =         DRV_NAME,
        .probe =        sddr09_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1779,4 +1785,4 @@ static struct usb_driver sddr09_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(sddr09_driver);
+module_usb_stor_driver(sddr09_driver, sddr09_host_template, DRV_NAME);
index aacedef9667cebcf0ef1992a5f05a0d600d0c9ff..e5e0a25ecd96306d0a115bab20f75c1be535a8e2 100644 (file)
@@ -34,6 +34,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-sddr55"
 
 MODULE_DESCRIPTION("Driver for SanDisk SDDR-55 SmartMedia reader");
 MODULE_AUTHOR("Simon Munton");
@@ -968,6 +971,7 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
        return USB_STOR_TRANSPORT_FAILED; // FIXME: sense buffer?
 }
 
+static struct scsi_host_template sddr55_host_template;
 
 static int sddr55_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
@@ -976,7 +980,8 @@ static int sddr55_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - sddr55_usb_ids) + sddr55_unusual_dev_list);
+                       (id - sddr55_usb_ids) + sddr55_unusual_dev_list,
+                       &sddr55_host_template);
        if (result)
                return result;
 
@@ -990,7 +995,7 @@ static int sddr55_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver sddr55_driver = {
-       .name =         "ums-sddr55",
+       .name =         DRV_NAME,
        .probe =        sddr55_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1003,4 +1008,4 @@ static struct usb_driver sddr55_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(sddr55_driver);
+module_usb_stor_driver(sddr55_driver, sddr55_host_template, DRV_NAME);
index 008d805c3d21cde7458058a6a2a5b0803da92bcf..a3ec86b913a10422587f8a9ba7011c97bd65bbd5 100644 (file)
@@ -53,6 +53,9 @@
 #include "transport.h"
 #include "protocol.h"
 #include "debug.h"
+#include "scsiglue.h"
+
+#define DRV_NAME "ums-usbat"
 
 MODULE_DESCRIPTION("Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable");
 MODULE_AUTHOR("Daniel Drake <dsd@gentoo.org>, Robert Baruch <autophile@starband.net>");
@@ -1834,6 +1837,8 @@ static int init_usbat_flash(struct us_data *us)
        return init_usbat(us, USBAT_DEV_FLASH);
 }
 
+static struct scsi_host_template usbat_host_template;
+
 static int usbat_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -1841,7 +1846,8 @@ static int usbat_probe(struct usb_interface *intf,
        int result;
 
        result = usb_stor_probe1(&us, intf, id,
-                       (id - usbat_usb_ids) + usbat_unusual_dev_list);
+                       (id - usbat_usb_ids) + usbat_unusual_dev_list,
+                       &usbat_host_template);
        if (result)
                return result;
 
@@ -1858,7 +1864,7 @@ static int usbat_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver usbat_driver = {
-       .name =         "ums-usbat",
+       .name =         DRV_NAME,
        .probe =        usbat_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1871,4 +1877,4 @@ static struct usb_driver usbat_driver = {
        .no_dynamic_id = 1,
 };
 
-module_usb_driver(usbat_driver);
+module_usb_stor_driver(usbat_driver, usbat_host_template, DRV_NAME);
index 6c10c888f35fb976b94b1ea3fddd61c4bcabe520..43576ed31ccdc4bfcfcafba0f95e6006a6bd63b6 100644 (file)
@@ -76,6 +76,8 @@
 #include "uas-detect.h"
 #endif
 
+#define DRV_NAME "usb-storage"
+
 /* Some informational data */
 MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
 MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
@@ -924,7 +926,8 @@ static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
 int usb_stor_probe1(struct us_data **pus,
                struct usb_interface *intf,
                const struct usb_device_id *id,
-               struct us_unusual_dev *unusual_dev)
+               struct us_unusual_dev *unusual_dev,
+               struct scsi_host_template *sht)
 {
        struct Scsi_Host *host;
        struct us_data *us;
@@ -936,7 +939,7 @@ int usb_stor_probe1(struct us_data **pus,
         * Ask the SCSI layer to allocate a host structure, with extra
         * space at the end for our private us_data structure.
         */
-       host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
+       host = scsi_host_alloc(sht, sizeof(*us));
        if (!host) {
                dev_warn(&intf->dev, "Unable to allocate the scsi host\n");
                return -ENOMEM;
@@ -1073,6 +1076,8 @@ void usb_stor_disconnect(struct usb_interface *intf)
 }
 EXPORT_SYMBOL_GPL(usb_stor_disconnect);
 
+static struct scsi_host_template usb_stor_host_template;
+
 /* The main probe routine for standard devices */
 static int storage_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
@@ -1113,7 +1118,8 @@ static int storage_probe(struct usb_interface *intf,
                        id->idVendor, id->idProduct);
        }
 
-       result = usb_stor_probe1(&us, intf, id, unusual_dev);
+       result = usb_stor_probe1(&us, intf, id, unusual_dev,
+                                &usb_stor_host_template);
        if (result)
                return result;
 
@@ -1124,7 +1130,7 @@ static int storage_probe(struct usb_interface *intf,
 }
 
 static struct usb_driver usb_storage_driver = {
-       .name =         "usb-storage",
+       .name =         DRV_NAME,
        .probe =        storage_probe,
        .disconnect =   usb_stor_disconnect,
        .suspend =      usb_stor_suspend,
@@ -1137,4 +1143,4 @@ static struct usb_driver usb_storage_driver = {
        .soft_unbind =  1,
 };
 
-module_usb_driver(usb_storage_driver);
+module_usb_stor_driver(usb_storage_driver, usb_stor_host_template, DRV_NAME);
index 307e339a9478682dc5b2709710bd5209cfef47ca..da0ad3241728a83d552ca60b40b6c63d9829c49c 100644 (file)
@@ -197,11 +197,25 @@ extern int usb_stor_post_reset(struct usb_interface *iface);
 extern int usb_stor_probe1(struct us_data **pus,
                struct usb_interface *intf,
                const struct usb_device_id *id,
-               struct us_unusual_dev *unusual_dev);
+               struct us_unusual_dev *unusual_dev,
+               struct scsi_host_template *sht);
 extern int usb_stor_probe2(struct us_data *us);
 extern void usb_stor_disconnect(struct usb_interface *intf);
 
 extern void usb_stor_adjust_quirks(struct usb_device *dev,
                unsigned long *fflags);
 
+#define module_usb_stor_driver(__driver, __sht, __name) \
+static int __init __driver##_init(void) \
+{ \
+       usb_stor_host_template_init(&(__sht), __name, THIS_MODULE); \
+       return usb_register(&(__driver)); \
+} \
+module_init(__driver##_init); \
+static void __exit __driver##_exit(void) \
+{ \
+       usb_deregister(&(__driver)); \
+} \
+module_exit(__driver##_exit)
+
 #endif