From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Hannes Reinecke <hare@suse.de>, Christoph Hellwig <hch@lst.de>,
"James E.J. Bottomley" <JBottomley@parallels.com>
Subject: [PATCH v6 4/4] scsi: esp_scsi: adjust module reference for scsi host
Date: Mon, 4 May 2015 23:46:09 +0900 [thread overview]
Message-ID: <1430750769-11405-5-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1430750769-11405-1-git-send-email-akinobu.mita@gmail.com>
While accessing a scsi device on host adapter supported by sub driver for
the ESP chip (mac_esp, am53c974, sun_esp, jazz_esp, sun3x_esp), the module
reference count is not incremented. Because these drivers allocate scsi
hosts with scsi_esp_template defined in ESP SCSI driver core module. So
these drivers always can be unloaded.
This fixes it by passing correct module reference to newly introduced
scsi_esp_host_alloc() so that .module field in struct Scsi_Host can be
adjusted.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: Hannes Reinecke <hare@suse.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
---
drivers/scsi/am53c974.c | 3 +--
drivers/scsi/esp_scsi.c | 16 +++++++++++++---
drivers/scsi/esp_scsi.h | 11 +++++++----
drivers/scsi/jazz_esp.c | 3 +--
drivers/scsi/mac_esp.c | 3 +--
drivers/scsi/sun3x_esp.c | 3 +--
drivers/scsi/sun_esp.c | 3 +--
7 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/drivers/scsi/am53c974.c b/drivers/scsi/am53c974.c
index beea30e..c1ba885 100644
--- a/drivers/scsi/am53c974.c
+++ b/drivers/scsi/am53c974.c
@@ -400,7 +400,6 @@ static void dc390_check_eeprom(struct esp *esp)
static int pci_esp_probe_one(struct pci_dev *pdev,
const struct pci_device_id *id)
{
- struct scsi_host_template *hostt = &scsi_esp_template;
int err = -ENODEV;
struct Scsi_Host *shost;
struct esp *esp;
@@ -417,7 +416,7 @@ static int pci_esp_probe_one(struct pci_dev *pdev,
goto fail_disable_device;
}
- shost = scsi_host_alloc(hostt, sizeof(struct esp));
+ shost = scsi_esp_host_alloc(sizeof(struct esp));
if (!shost) {
dev_printk(KERN_INFO, &pdev->dev,
"failed to allocate scsi host\n");
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 065b25d..4484c90 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -2675,8 +2675,7 @@ static const char *esp_info(struct Scsi_Host *host)
return "esp";
}
-struct scsi_host_template scsi_esp_template = {
- .module = THIS_MODULE,
+static struct scsi_host_template scsi_esp_template = {
.name = "esp",
.info = esp_info,
.queuecommand = esp_queuecommand,
@@ -2696,7 +2695,18 @@ struct scsi_host_template scsi_esp_template = {
.skip_settle_delay = 1,
.use_blk_tags = 1,
};
-EXPORT_SYMBOL(scsi_esp_template);
+
+struct Scsi_Host *__scsi_esp_host_alloc(int privsize, struct module *owner)
+{
+ struct Scsi_Host *shost;
+
+ shost = scsi_host_alloc(&scsi_esp_template, privsize);
+ if (shost)
+ shost->module = owner;
+
+ return shost;
+}
+EXPORT_SYMBOL(__scsi_esp_host_alloc);
static void esp_get_signalling(struct Scsi_Host *host)
{
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index 84dcbe4..9309e08 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -544,9 +544,8 @@ struct esp {
/* A front-end driver for the ESP chip should do the following in
* it's device probe routine:
- * 1) Allocate the host and private area using scsi_host_alloc()
- * with size 'sizeof(struct esp)'. The first argument to
- * scsi_host_alloc() should be &scsi_esp_template.
+ * 1) Allocate the host and private area using scsi_esp_host_alloc()
+ * with size 'sizeof(struct esp)'.
* 2) Set host->max_id as appropriate.
* 3) Set esp->host to the scsi_host itself, and esp->dev
* to the device object pointer.
@@ -573,7 +572,11 @@ struct esp {
* 13) Check scsi_esp_register() return value, release all resources
* if an error was returned.
*/
-extern struct scsi_host_template scsi_esp_template;
+extern struct Scsi_Host *__scsi_esp_host_alloc(int privsize,
+ struct module *owner);
+#define scsi_esp_host_alloc(privsize) \
+ __scsi_esp_host_alloc(privsize, THIS_MODULE)
+
extern int scsi_esp_register(struct esp *, struct device *);
extern void scsi_esp_unregister(struct esp *);
diff --git a/drivers/scsi/jazz_esp.c b/drivers/scsi/jazz_esp.c
index 9aaa74e..9c268f7 100644
--- a/drivers/scsi/jazz_esp.c
+++ b/drivers/scsi/jazz_esp.c
@@ -131,13 +131,12 @@ static const struct esp_driver_ops jazz_esp_ops = {
static int esp_jazz_probe(struct platform_device *dev)
{
- struct scsi_host_template *tpnt = &scsi_esp_template;
struct Scsi_Host *host;
struct esp *esp;
struct resource *res;
int err;
- host = scsi_host_alloc(tpnt, sizeof(struct esp));
+ host = scsi_esp_host_alloc(sizeof(struct esp));
err = -ENOMEM;
if (!host)
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index 14c0334..ad4ad71 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -483,7 +483,6 @@ static struct esp_driver_ops mac_esp_ops = {
static int esp_mac_probe(struct platform_device *dev)
{
- struct scsi_host_template *tpnt = &scsi_esp_template;
struct Scsi_Host *host;
struct esp *esp;
int err;
@@ -495,7 +494,7 @@ static int esp_mac_probe(struct platform_device *dev)
if (dev->id > 1)
return -ENODEV;
- host = scsi_host_alloc(tpnt, sizeof(struct esp));
+ host = scsi_esp_host_alloc(sizeof(struct esp));
err = -ENOMEM;
if (!host)
diff --git a/drivers/scsi/sun3x_esp.c b/drivers/scsi/sun3x_esp.c
index e26e81d..adb4368 100644
--- a/drivers/scsi/sun3x_esp.c
+++ b/drivers/scsi/sun3x_esp.c
@@ -196,13 +196,12 @@ static const struct esp_driver_ops sun3x_esp_ops = {
static int esp_sun3x_probe(struct platform_device *dev)
{
- struct scsi_host_template *tpnt = &scsi_esp_template;
struct Scsi_Host *host;
struct esp *esp;
struct resource *res;
int err = -ENOMEM;
- host = scsi_host_alloc(tpnt, sizeof(struct esp));
+ host = scsi_esp_host_alloc(sizeof(struct esp));
if (!host)
goto fail;
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index 7b6d4c2..1449bea 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -489,12 +489,11 @@ static const struct esp_driver_ops sbus_esp_ops = {
static int esp_sbus_probe_one(struct platform_device *op,
struct platform_device *espdma, int hme)
{
- struct scsi_host_template *tpnt = &scsi_esp_template;
struct Scsi_Host *host;
struct esp *esp;
int err;
- host = scsi_host_alloc(tpnt, sizeof(struct esp));
+ host = scsi_esp_host_alloc(sizeof(struct esp));
err = -ENOMEM;
if (!host)
--
1.9.1
next prev parent reply other threads:[~2015-05-04 14:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-04 14:46 [PATCH v6 0/4] scsi: ufs & ums-* & esp_scsi: fix module reference counting Akinobu Mita
2015-05-04 14:46 ` [PATCH v6 1/4] scsi: add ability to adjust module reference for scsi host Akinobu Mita
2015-05-04 14:46 ` [PATCH v6 2/4] scsi: ufs: " Akinobu Mita
[not found] ` <1430750769-11405-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-04 14:46 ` [PATCH v6 3/4] usb: storage: " Akinobu Mita
2015-05-04 14:46 ` Akinobu Mita [this message]
2015-05-04 15:15 ` [PATCH v6 0/4] scsi: ufs & ums-* & esp_scsi: fix module reference counting James Bottomley
[not found] ` <1430752523.2177.15.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-05-04 15:30 ` Hannes Reinecke
2015-05-04 20:09 ` Alan Stern
2015-05-04 21:41 ` James Bottomley
[not found] ` <1430775664.2177.36.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-05-05 13:39 ` Akinobu Mita
2015-05-05 15:35 ` James Bottomley
2015-05-05 14:25 ` Alan Stern
2015-05-05 18:05 ` James Bottomley
2015-05-05 19:14 ` Alan Stern
2015-05-05 21:42 ` James Bottomley
2015-05-06 9:26 ` Akinobu Mita
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430750769-11405-5-git-send-email-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=JBottomley@parallels.com \
--cc=davem@davemloft.net \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox