Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa519be3 authored by Akinobu Mita's avatar Akinobu Mita Committed by Greg Kroah-Hartman
Browse files

usb: storage: fix module reference for scsi host



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: default avatarAkinobu 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: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1cb39e25
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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);
+7 −3
Original line number Diff line number Diff line
@@ -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 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
		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);
+9 −3
Original line number Diff line number Diff line
@@ -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);
+8 −3
Original line number Diff line number Diff line
@@ -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);
+9 −3
Original line number Diff line number Diff line
@@ -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);
Loading