From patchwork Mon May 4 14:46:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6327241 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 61152BEEE1 for ; Mon, 4 May 2015 14:46:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5429120351 for ; Mon, 4 May 2015 14:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35E43202E6 for ; Mon, 4 May 2015 14:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751612AbbEDOqn (ORCPT ); Mon, 4 May 2015 10:46:43 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:35138 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751576AbbEDOqm (ORCPT ); Mon, 4 May 2015 10:46:42 -0400 Received: by pdbqd1 with SMTP id qd1so165001053pdb.2 for ; Mon, 04 May 2015 07:46:42 -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:in-reply-to:references; bh=fYkJ+BAg6WJt9bwxClYoUZhZXKLnh/6M0gC/M/yYnas=; b=kf1VDL1fLSUAW96eW4qpBY7LxYdDSb6tw6tdWffLmfYxDA3hLduub3qHIfDk01fRae qYjoKnbB9PixIjuP5PalefJQJxFKBaofuH5jDZOBHcQW6u+FRH4BuCB/5jK3N+WhN8Ld dwxfAh2o3WvEejHWkFoToPVbaDR6MsfOQiRHi/GvaGcLoQO91alR0LBoIj9+5MiR4Kzw qLt0V4a8K5VRBTdmjD8g6yicgr+y0zwJoxqaQayR9Gxlqm/hO86UWZAX5osovXujiepc tYnyNhTuxj2wU1UyMjIyGTXHQEeAqK91zg/5oFgQiezsY/1sOD7nrulZs1KFqDd+jmC9 b4bQ== X-Received: by 10.68.167.131 with SMTP id zo3mr42671383pbb.123.1430750802032; Mon, 04 May 2015 07:46:42 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id om10sm13036162pbb.58.2015.05.04.07.46.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 May 2015 07:46:40 -0700 (PDT) From: Akinobu Mita To: linux-scsi@vger.kernel.org Cc: Akinobu Mita , "David S. Miller" , Hannes Reinecke , Christoph Hellwig , "James E.J. Bottomley" Subject: [PATCH v6 4/4] scsi: esp_scsi: adjust module reference for scsi host Date: Mon, 4 May 2015 23:46:09 +0900 Message-Id: <1430750769-11405-5-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430750769-11405-1-git-send-email-akinobu.mita@gmail.com> References: <1430750769-11405-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 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 Acked-by: David S. Miller Acked-by: Hannes Reinecke Cc: "David S. Miller" Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: "James E.J. Bottomley" 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)