public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <robert.w.love@intel.com>
To: James.Bottomley@suse.de, linux-scsi@vger.kernel.org
Cc: Ross Brattain <ross.b.brattain@intel.com>
Subject: [PATCH 07/28] fcoe: Fix module reference count for vports
Date: Fri, 28 Jan 2011 16:03:47 -0800	[thread overview]
Message-ID: <20110129000347.1784.60143.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20110129000310.1784.58748.stgit@localhost6.localdomain6>

vports are not grabbing module references but are
releasing them. This causes the module reference count
to decrement too many times and it wraps around past 0.

The solution is to do a module_put() in
fcoe_interface_release() so that the reference is only
released when the fcoe_interface is released. There is a
one-to-one relationship between the N_Port and the
fcoe_interface, so the module reference will only be
dropped when the N_Port is destroyed

To create symetry in the code this patch moves the
try_module_get() call into fcoe_interface_create(). This
means that only the N_Port will grab a reference to the
module when its corresponding fcoe_interface is created.

This patch also makes it so that the fcoe_interface_create()
routine encodes any error codes in the fcoe_interface
pointer returned. This way its caller, fcoe_create(), can
return an accurate error code.

Signed-off-by: Robert Love <robert.w.love@intel.com>
Tested-by: Ross Brattain <ross.b.brattain@intel.com>
---
 drivers/scsi/fcoe/fcoe.c |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 9f9600b..452b421 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -356,10 +356,18 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 	struct fcoe_interface *fcoe;
 	int err;
 
+	if (!try_module_get(THIS_MODULE)) {
+		FCOE_NETDEV_DBG(netdev,
+				"Could not get a reference to the module\n");
+		fcoe = ERR_PTR(-EBUSY);
+		goto out;
+	}
+
 	fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
 	if (!fcoe) {
 		FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
-		return NULL;
+		fcoe = ERR_PTR(-ENOMEM);
+		goto out_nomod;
 	}
 
 	dev_hold(netdev);
@@ -378,9 +386,15 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
 		fcoe_ctlr_destroy(&fcoe->ctlr);
 		kfree(fcoe);
 		dev_put(netdev);
-		return NULL;
+		fcoe = ERR_PTR(err);
+		goto out_nomod;
 	}
 
+	goto out;
+
+out_nomod:
+	module_put(THIS_MODULE);
+out:
 	return fcoe;
 }
 
@@ -442,6 +456,7 @@ static void fcoe_interface_release(struct kref *kref)
 	fcoe_ctlr_destroy(&fcoe->ctlr);
 	kfree(fcoe);
 	dev_put(netdev);
+	module_put(THIS_MODULE);
 }
 
 /**
@@ -886,7 +901,6 @@ static void fcoe_if_destroy(struct fc_lport *lport)
 
 	/* Release the Scsi_Host */
 	scsi_host_put(lport->host);
-	module_put(THIS_MODULE);
 }
 
 /**
@@ -2135,15 +2149,10 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
 	 */
 	if (THIS_MODULE->state != MODULE_STATE_LIVE) {
 		rc = -ENODEV;
-		goto out_nomod;
+		goto out_nodev;
 	}
 #endif
 
-	if (!try_module_get(THIS_MODULE)) {
-		rc = -EINVAL;
-		goto out_nomod;
-	}
-
 	netdev = fcoe_if_to_netdev(buffer);
 	if (!netdev) {
 		rc = -ENODEV;
@@ -2157,8 +2166,8 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
 	}
 
 	fcoe = fcoe_interface_create(netdev, fip_mode);
-	if (!fcoe) {
-		rc = -ENOMEM;
+	if (IS_ERR(fcoe)) {
+		rc = PTR_ERR(fcoe);
 		goto out_putdev;
 	}
 
@@ -2198,8 +2207,6 @@ out_free:
 out_putdev:
 	dev_put(netdev);
 out_nodev:
-	module_put(THIS_MODULE);
-out_nomod:
 	rtnl_unlock();
 	mutex_unlock(&fcoe_config_mutex);
 	return rc;


  parent reply	other threads:[~2011-01-29  0:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29  0:03 [PATCH 00/28] libfc/libfcoe/fcoe updates for scsi-misc (2.6.39) Robert Love
2011-01-29  0:03 ` [PATCH 01/28] libfc: always initialize the FCoE DDP exchange id for fsp as FC_XID_UNKNOWN Robert Love
2011-01-29  0:03 ` [PATCH 02/28] libfc: Return a valid return code in fc_fcp_pkt_abort() Robert Love
2011-01-29  0:03 ` [PATCH 03/28] libfc: Cleanup return paths in fc_rport_error_retry Robert Love
2011-01-29  0:03 ` [PATCH 04/28] libfc: dereferencing ERR_PTR in fc_tm_done() Robert Love
2011-01-29  0:03 ` [PATCH 05/28] fnic: fix memory leak Robert Love
2011-01-29  0:03 ` [PATCH 06/28] fnic: Bumping up fnic version from 1.4.0.145 to 1.5.0.1 Robert Love
2011-01-29  0:03 ` Robert Love [this message]
2011-01-29  0:03 ` [PATCH 08/28] fcoe: drop FCoE LOGO in FIP mode Robert Love
2011-01-29  0:03 ` [PATCH 09/28] libfc: fix sparse static and non-ANSI warnings Robert Love
2011-01-29  0:04 ` [PATCH 10/28] libfc: add hook for FC-4 provider registration Robert Love
2011-01-29  0:04 ` [PATCH 11/28] libfc: add method for setting handler for incoming exchange Robert Love
2011-01-29  0:04 ` [PATCH 12/28] libfc: add local port hook for provider session lookup Robert Love
2011-01-29  0:04 ` [PATCH 13/28] libfc: add hook to notify providers of local port changes Robert Love
2011-01-29  0:04 ` [PATCH 14/28] libfc: use PRLI hook to get parameters when sending outgoing PRLI Robert Love
2011-01-29  0:04 ` [PATCH 15/28] libfc: Remove usage of the Scsi_Host's host_lock Robert Love
2011-01-29  0:04 ` [PATCH 16/28] libfc: export seq_release() for users of seq_assign() Robert Love
2011-01-29  0:04 ` [PATCH 17/28] libfc: Enhanced exchange ID selection mechanism and fix related EMA selection logic Robert Love
2011-01-29  0:04 ` [PATCH 18/28] libfcoe: move logging macros into the local libfcoe.h header file Robert Love
2011-01-29  0:04 ` [PATCH 19/28] libfcoe: add fcoe_transport structure defines to include/scsi/libfcoe.h Robert Love
2011-01-29  0:04 ` [PATCH 20/28] libfcoe: add implementation to support fcoe transport Robert Love
2011-02-02  6:43   ` Mike Christie
2011-02-03  2:13     ` Robert Love
2011-01-29  0:05 ` [PATCH 21/28] libfcoe: rename libfcoe.c to fcoe_cltr.c for the coming fcoe_transport.c Robert Love
2011-01-29  0:05 ` [PATCH 22/28] libfcoe: include fcoe_transport.c into kernel libfcoe module Robert Love
2011-01-29  0:05 ` [PATCH 23/28] fcoe: prepare fcoe for using fcoe transport Robert Love
2011-01-29  0:05 ` [PATCH 24/28] fcoe: convert fcoe.ko to become an fcoe transport provider driver Robert Love
2011-01-29  0:05 ` [PATCH 25/28] libfc: Extending lport's roles for target if there is a registered target Robert Love
2011-01-29  0:05 ` [PATCH 26/28] libfc: introduce LLD event callback Robert Love
2011-01-29  0:05 ` [PATCH 27/28] fcoe: use dedicated workqueue instead of system_wq Robert Love
2011-01-29  0:05 ` [PATCH 28/28] libfcoe: Move common code from fcoe to libfcoe module Robert Love

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=20110129000347.1784.60143.stgit@localhost6.localdomain6 \
    --to=robert.w.love@intel.com \
    --cc=James.Bottomley@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=ross.b.brattain@intel.com \
    /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