linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
To: james.bottomley@hansenpartnership.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	smcameron@yahoo.com, thenzl@redhat.com,
	akpm@linux-foundation.org, mikem@beardog.cce.hp.com
Subject: [PATCH 07/16] hpsa: factor out cmd pool allocation functions
Date: Tue, 03 May 2011 14:59:20 -0500	[thread overview]
Message-ID: <20110503195920.5478.66719.stgit@beardog.cce.hp.com> (raw)
In-Reply-To: <20110503195750.5478.54853.stgit@beardog.cce.hp.com>

From: Stephen M. Cameron <scameron@beardog.cce.hp.com>

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
---
 drivers/scsi/hpsa.c |   66 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 2aeb210..7336f3c 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -3847,6 +3847,40 @@ static __devinit int hpsa_init_reset_devices(struct pci_dev *pdev)
 	return 0;
 }
 
+static __devinit int hpsa_allocate_cmd_pool(struct ctlr_info *h)
+{
+	h->cmd_pool_bits = kzalloc(
+		DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
+		sizeof(unsigned long), GFP_KERNEL);
+	h->cmd_pool = pci_alloc_consistent(h->pdev,
+		    h->nr_cmds * sizeof(*h->cmd_pool),
+		    &(h->cmd_pool_dhandle));
+	h->errinfo_pool = pci_alloc_consistent(h->pdev,
+		    h->nr_cmds * sizeof(*h->errinfo_pool),
+		    &(h->errinfo_pool_dhandle));
+	if ((h->cmd_pool_bits == NULL)
+	    || (h->cmd_pool == NULL)
+	    || (h->errinfo_pool == NULL)) {
+		dev_err(&h->pdev->dev, "out of memory in %s", __func__);
+		return -ENOMEM;
+	}
+	return 0;
+}
+
+static void hpsa_free_cmd_pool(struct ctlr_info *h)
+{
+	kfree(h->cmd_pool_bits);
+	if (h->cmd_pool)
+		pci_free_consistent(h->pdev,
+			    h->nr_cmds * sizeof(struct CommandList),
+			    h->cmd_pool, h->cmd_pool_dhandle);
+	if (h->errinfo_pool)
+		pci_free_consistent(h->pdev,
+			    h->nr_cmds * sizeof(struct ErrorInfo),
+			    h->errinfo_pool,
+			    h->errinfo_pool_dhandle);
+}
+
 static int __devinit hpsa_init_one(struct pci_dev *pdev,
 				    const struct pci_device_id *ent)
 {
@@ -3917,33 +3951,14 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
 	dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n",
 	       h->devname, pdev->device,
 	       h->intr[h->intr_mode], dac ? "" : " not");
-
-	h->cmd_pool_bits =
-	    kmalloc(((h->nr_cmds + BITS_PER_LONG -
-		      1) / BITS_PER_LONG) * sizeof(unsigned long), GFP_KERNEL);
-	h->cmd_pool = pci_alloc_consistent(h->pdev,
-		    h->nr_cmds * sizeof(*h->cmd_pool),
-		    &(h->cmd_pool_dhandle));
-	h->errinfo_pool = pci_alloc_consistent(h->pdev,
-		    h->nr_cmds * sizeof(*h->errinfo_pool),
-		    &(h->errinfo_pool_dhandle));
-	if ((h->cmd_pool_bits == NULL)
-	    || (h->cmd_pool == NULL)
-	    || (h->errinfo_pool == NULL)) {
-		dev_err(&pdev->dev, "out of memory");
-		rc = -ENOMEM;
+	if (hpsa_allocate_cmd_pool(h))
 		goto clean4;
-	}
 	if (hpsa_allocate_sg_chain_blocks(h))
 		goto clean4;
 	init_waitqueue_head(&h->scan_wait_queue);
 	h->scan_finished = 1; /* no scan currently in progress */
 
 	pci_set_drvdata(pdev, h);
-	memset(h->cmd_pool_bits, 0,
-	       ((h->nr_cmds + BITS_PER_LONG -
-		 1) / BITS_PER_LONG) * sizeof(unsigned long));
-
 	hpsa_scsi_setup(h);
 
 	/* Turn the interrupts on so we can service requests */
@@ -3957,16 +3972,7 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
 
 clean4:
 	hpsa_free_sg_chain_blocks(h);
-	kfree(h->cmd_pool_bits);
-	if (h->cmd_pool)
-		pci_free_consistent(h->pdev,
-			    h->nr_cmds * sizeof(struct CommandList),
-			    h->cmd_pool, h->cmd_pool_dhandle);
-	if (h->errinfo_pool)
-		pci_free_consistent(h->pdev,
-			    h->nr_cmds * sizeof(struct ErrorInfo),
-			    h->errinfo_pool,
-			    h->errinfo_pool_dhandle);
+	hpsa_free_cmd_pool(h);
 	free_irq(h->intr[h->intr_mode], h);
 clean2:
 clean1:

  parent reply	other threads:[~2011-05-03 19:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03 19:58 [PATCH 00/16] hpsa: May 3, 2011 updates Stephen M. Cameron
2011-05-03 19:58 ` [PATCH 01/16] hpsa: do readl after writel in main i/o path to ensure commands don't get lost Stephen M. Cameron
2011-05-04 11:15   ` Tomas Henzl
2011-05-04 12:52     ` scameron
2011-05-04 13:34       ` Tomas Henzl
2011-05-04 17:28       ` Valdis.Kletnieks
2011-05-04 17:37         ` Matthew Wilcox
2011-05-04 17:54           ` Valdis.Kletnieks
2011-05-05 18:35             ` Mike Miller
2011-05-23 11:37               ` Tomas Henzl
2011-05-25 15:20                 ` Miller, Mike (OS Dev)
2011-05-26 12:13                   ` Tomas Henzl
2011-05-26 14:53                     ` Miller, Mike (OS Dev)
2011-05-03 19:58 ` [PATCH 02/16] hpsa: add readl after writel in interrupt mask setting code Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 03/16] hpsa: remove unused parameter from hpsa_complete_scsi_command() Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 04/16] hpsa: delete old unused padding garbage Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 05/16] hpsa: do a better job of detecting controller reset failure Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 06/16] hpsa: wait longer for no-op to complete after resetting controller Stephen M. Cameron
2011-05-03 19:59 ` Stephen M. Cameron [this message]
2011-05-03 19:59 ` [PATCH 08/16] hpsa: factor out irq request code Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 09/16] hpsa: increase time to wait for board reset Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 10/16] hpsa: clarify messages around reset behavior Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 11/16] hpsa: remove atrophied hpsa_scsi_setup function Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 12/16] hpsa: use new doorbell-bit-5 reset method Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 13/16] hpsa: do soft reset if hard reset is broken Stephen M. Cameron
2011-05-03 19:59 ` [PATCH 14/16] hpsa: remove superfluous sleeps around reset code Stephen M. Cameron
2011-05-03 20:00 ` [PATCH 15/16] hpsa: do not attempt PCI power management reset method if we know it won't work Stephen M. Cameron
2011-05-03 20:00 ` [PATCH 16/16] hpsa: add P2000 to list of shared SAS devices Stephen M. Cameron
2011-05-17 10:12   ` James Bottomley
2011-05-17 13:26     ` scameron

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=20110503195920.5478.66719.stgit@beardog.cce.hp.com \
    --to=scameron@beardog.cce.hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mikem@beardog.cce.hp.com \
    --cc=smcameron@yahoo.com \
    --cc=thenzl@redhat.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;
as well as URLs for NNTP newsgroup(s).