From patchwork Mon May 4 14:46:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6327231 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F17F49F32B for ; Mon, 4 May 2015 14:46:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07FA920351 for ; Mon, 4 May 2015 14:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C399520376 for ; Mon, 4 May 2015 14:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751548AbbEDOqj (ORCPT ); Mon, 4 May 2015 10:46:39 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:34167 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750899AbbEDOqj (ORCPT ); Mon, 4 May 2015 10:46:39 -0400 Received: by pdbqa5 with SMTP id qa5so164849513pdb.1; Mon, 04 May 2015 07:46: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:in-reply-to:references; bh=HxMc1Qnn3lAHB0mNVePhE8YofldIbamYVKbRN4sY8ok=; b=ju2vTIGnnySt9h9pET3Dr5ciW880iHxjRHqZ+3I+7dQNA5f6QunasndFvJx5GydBfP UqV4Nn1DA0yUSmqLL6m6DE6QIMX0jZepeDzhjUmmSfCOeNtAKa3FdfkRFTgojcDDPN/w GDqw35vUFvEDINX208UYcPtFQCVLVzoyy+Nv+sJ37ULD5Q66KFME7UDpy1x8px7EiHqB nnEixj2d47OLEx9qskqxoMDboRgju9w/FikF8lO/vIRRe9xsgqGfPQNWSYcLImp9Fug9 nGIS4I9OtwmX5JXmrZJkIRIZcl5MacYxK8/+mogV7l+PF6+Y2aoyaaNkXuPUBhS5ve4F A+Lw== X-Received: by 10.68.139.103 with SMTP id qx7mr42943261pbb.133.1430750798655; Mon, 04 May 2015 07:46:38 -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.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 May 2015 07:46:37 -0700 (PDT) From: Akinobu Mita To: linux-scsi@vger.kernel.org Cc: Akinobu Mita , Matthew Dharm , Greg Kroah-Hartman , Alan Stern , Christoph Hellwig , "James E.J. Bottomley" , linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Subject: [PATCH v6 3/4] usb: storage: adjust module reference for scsi host Date: Mon, 4 May 2015 23:46:08 +0900 Message-Id: <1430750769-11405-4-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 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 passing correct module reference to usb_stor_probe1() so that .module field in struct Scsi_Host can be adjusted. Signed-off-by: Akinobu Mita Acked-by: Alan Stern Cc: Matthew Dharm Cc: Greg Kroah-Hartman Cc: Alan Stern Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: linux-usb@vger.kernel.org Cc: usb-storage@lists.one-eyed-alien.net Cc: linux-scsi@vger.kernel.org --- drivers/usb/storage/usb.c | 8 +++++--- drivers/usb/storage/usb.h | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 6c10c88..711cdee 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -921,10 +921,11 @@ static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf) } /* First part of general USB mass-storage probing */ -int usb_stor_probe1(struct us_data **pus, +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 module *owner) { struct Scsi_Host *host; struct us_data *us; @@ -947,6 +948,7 @@ int usb_stor_probe1(struct us_data **pus, */ host->max_cmd_len = 16; host->sg_tablesize = usb_stor_sg_tablesize(intf); + host->module = owner; *pus = us = host_to_us(host); mutex_init(&(us->dev_mutex)); us_set_lock_class(&us->dev_mutex, intf); @@ -979,7 +981,7 @@ BadDevice: release_everything(us); return result; } -EXPORT_SYMBOL_GPL(usb_stor_probe1); +EXPORT_SYMBOL_GPL(__usb_stor_probe1); /* Second part of general USB mass-storage probing */ int usb_stor_probe2(struct us_data *us) diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h index 307e339..0cb74ba 100644 --- a/drivers/usb/storage/usb.h +++ b/drivers/usb/storage/usb.h @@ -194,10 +194,13 @@ extern int usb_stor_reset_resume(struct usb_interface *iface); extern int usb_stor_pre_reset(struct usb_interface *iface); extern int usb_stor_post_reset(struct usb_interface *iface); -extern int usb_stor_probe1(struct us_data **pus, +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 module *owner); +#define usb_stor_probe1(pus, intf, id, unusual_dev) \ + __usb_stor_probe1(pus, intf, id, unusual_dev, THIS_MODULE) extern int usb_stor_probe2(struct us_data *us); extern void usb_stor_disconnect(struct usb_interface *intf);