From patchwork Wed May 6 09:24:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6347911 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D25F4BEEE1 for ; Wed, 6 May 2015 09:24:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B84D200D0 for ; Wed, 6 May 2015 09:24:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F61120212 for ; Wed, 6 May 2015 09:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752405AbbEFJYr (ORCPT ); Wed, 6 May 2015 05:24:47 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:33223 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752315AbbEFJYi (ORCPT ); Wed, 6 May 2015 05:24:38 -0400 Received: by pacwv17 with SMTP id wv17so4268996pac.0; Wed, 06 May 2015 02:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=5dXrKEqAkJFDEx5JXJrRUc1iMgzRdva6DvBcigqbPY4=; b=IaRTxO1KOoiA6557pFXSDlCOQkxyoY1DT+ITPDrwsmZcKr17JOwXfSYA9iTwsP7gmL OUL5afZ+HMfknpR006mL/DKO8nL4pFh2Rfa/0y5aFSEvZXsdoAuhNDIqZnMyuh/ifZaX YrQhV4hcNYZEXKZdsL5RCEzKi6dZbPTZXQiHiP3arGaTGUvxcnfktCg+0WXbp4x2pmOe 3VEHGAF7T5c573cRgyZxuELEbKswPKCTFAga7gWmw6rrozF3vX+VBo2aBiU6dCktMN6a s1fsr51s6T2w9eZCTwjKGCsSQ0m0CHCT4c6IORI4EnaQIrnTGJoM9uBpDza71MxMJWfY ZR4w== X-Received: by 10.68.115.42 with SMTP id jl10mr60344200pbb.39.1430904277998; Wed, 06 May 2015 02:24:37 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id rd7sm1328478pdb.64.2015.05.06.02.24.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 May 2015 02:24:36 -0700 (PDT) From: Akinobu Mita To: linux-scsi@vger.kernel.org Cc: Akinobu Mita , Vinayak Holikatti , Dolev Raviv , Sujit Reddy Thumma , Subhash Jadavani , Christoph Hellwig , "James E.J. Bottomley" , Matthew Dharm , Greg Kroah-Hartman , Alan Stern , "David S. Miller" , Hannes Reinecke , linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Subject: [PATCH] usb: storage: fix module reference for scsi host Date: Wed, 6 May 2015 18:24:21 +0900 Message-Id: <1430904261-5049-1-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Vinayak Holikatti Cc: Dolev Raviv Cc: Sujit Reddy Thumma Cc: Subhash Jadavani Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: Matthew Dharm Cc: Greg Kroah-Hartman Cc: Alan Stern Cc: "David S. Miller" Cc: Hannes Reinecke Cc: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net Cc: linux-scsi@vger.kernel.org Acked-by: Alan Stern --- drivers/usb/storage/alauda.c | 12 +++++++++--- drivers/usb/storage/cypress_atacb.c | 10 +++++++--- drivers/usb/storage/datafab.c | 12 +++++++++--- drivers/usb/storage/ene_ub6250.c | 11 ++++++++--- drivers/usb/storage/freecom.c | 12 +++++++++--- drivers/usb/storage/isd200.c | 11 ++++++++--- drivers/usb/storage/jumpshot.c | 11 ++++++++--- drivers/usb/storage/karma.c | 12 +++++++++--- drivers/usb/storage/onetouch.c | 12 +++++++++--- drivers/usb/storage/realtek_cr.c | 12 +++++++++--- drivers/usb/storage/scsiglue.c | 12 +++++++++++- drivers/usb/storage/scsiglue.h | 3 ++- drivers/usb/storage/sddr09.c | 12 +++++++++--- drivers/usb/storage/sddr55.c | 11 ++++++++--- drivers/usb/storage/shuttle_usbat.c | 12 +++++++++--- drivers/usb/storage/usb.c | 16 +++++++++++----- drivers/usb/storage/usb.h | 16 +++++++++++++++- 17 files changed, 150 insertions(+), 47 deletions(-) diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c index 4b55ab6..171fa7d 100644 --- a/drivers/usb/storage/alauda.c +++ b/drivers/usb/storage/alauda.c @@ -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 "); @@ -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); diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c index b3466d1..c80d3de 100644 --- a/drivers/usb/storage/cypress_atacb.c +++ b/drivers/usb/storage/cypress_atacb.c @@ -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 "); 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); diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c index 7b17c21..aa4f519 100644 --- a/drivers/usb/storage/datafab.c +++ b/drivers/usb/storage/datafab.c @@ -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 "); @@ -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); diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c index 56f782b..f3cf4ce 100644 --- a/drivers/usb/storage/ene_ub6250.c +++ b/drivers/usb/storage/ene_ub6250.c @@ -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); diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c index ef16068..3f2b089 100644 --- a/drivers/usb/storage/freecom.c +++ b/drivers/usb/storage/freecom.c @@ -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 "); @@ -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); diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c index 0761786..1bac215 100644 --- a/drivers/usb/storage/isd200.c +++ b/drivers/usb/storage/isd200.c @@ -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 "); 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); diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c index 563078b..ee613e2 100644 --- a/drivers/usb/storage/jumpshot.c +++ b/drivers/usb/storage/jumpshot.c @@ -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 "); @@ -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); diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c index 94d16ee..ae201e6 100644 --- a/drivers/usb/storage/karma.c +++ b/drivers/usb/storage/karma.c @@ -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 , Keith Bennett "); @@ -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); diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index 74e2aa2..acc3d03 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c @@ -35,6 +35,9 @@ #include #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 "); @@ -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); diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c index 27e4a58..2043356 100644 --- a/drivers/usb/storage/realtek_cr.c +++ b/drivers/usb/storage/realtek_cr.c @@ -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 "); @@ -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); diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 0e400f3..5c0bfd5 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -540,7 +540,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", @@ -592,6 +592,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 */ diff --git a/drivers/usb/storage/scsiglue.h b/drivers/usb/storage/scsiglue.h index ffa1cca..5494d87 100644 --- a/drivers/usb/storage/scsiglue.h +++ b/drivers/usb/storage/scsiglue.h @@ -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 diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index 3847053..b746036 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c @@ -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 , Robert Baruch "); @@ -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); diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c index aacedef..e5e0a25 100644 --- a/drivers/usb/storage/sddr55.c +++ b/drivers/usb/storage/sddr55.c @@ -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); diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c index 008d805..a3ec86b 100644 --- a/drivers/usb/storage/shuttle_usbat.c +++ b/drivers/usb/storage/shuttle_usbat.c @@ -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 , Robert Baruch "); @@ -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); diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 6c10c88..43576ed 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -76,6 +76,8 @@ #include "uas-detect.h" #endif +#define DRV_NAME "usb-storage" + /* Some informational data */ MODULE_AUTHOR("Matthew Dharm "); 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); diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h index 307e339..da0ad32 100644 --- a/drivers/usb/storage/usb.h +++ b/drivers/usb/storage/usb.h @@ -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