From: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
To: axboe@kernel.dk
Cc: mikem@beardog.cce.hp.com, akpm@linux-foundation.org,
thenzl@redhat.com, linux-kernel@vger.kernel.org,
smcameron@yahoo.com
Subject: [PATCH 03/16] cciss: factor out command pool allocation functions
Date: Tue, 03 May 2011 14:53:05 -0500 [thread overview]
Message-ID: <20110503195305.5154.73383.stgit@beardog.cce.hp.com> (raw)
In-Reply-To: <20110503194919.5154.78352.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/block/cciss.c | 67 ++++++++++++++++++++++++++-----------------------
1 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index ed6aa83..152cb40 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -4653,6 +4653,39 @@ static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
return 0;
}
+static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h)
+{
+ h->cmd_pool_bits = kmalloc(
+ 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(CommandList_struct),
+ &(h->cmd_pool_dhandle));
+ h->errinfo_pool = pci_alloc_consistent(h->pdev,
+ h->nr_cmds * sizeof(ErrorInfo_struct),
+ &(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");
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+static void cciss_free_cmd_pool(ctlr_info_t *h)
+{
+ kfree(h->cmd_pool_bits);
+ if (h->cmd_pool)
+ pci_free_consistent(h->pdev,
+ h->nr_cmds * sizeof(CommandList_struct),
+ h->cmd_pool, h->cmd_pool_dhandle);
+ if (h->errinfo_pool)
+ pci_free_consistent(h->pdev,
+ h->nr_cmds * sizeof(ErrorInfo_struct),
+ h->errinfo_pool, h->errinfo_pool_dhandle);
+}
+
/*
* This is it. Find all the controllers and register them. I really hate
* stealing all these major device numbers.
@@ -4745,23 +4778,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
h->devname, pdev->device, pci_name(pdev),
h->intr[PERF_MODE_INT], dac ? "" : " not");
- h->cmd_pool_bits =
- kmalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
- * sizeof(unsigned long), GFP_KERNEL);
- h->cmd_pool = (CommandList_struct *)
- pci_alloc_consistent(h->pdev,
- h->nr_cmds * sizeof(CommandList_struct),
- &(h->cmd_pool_dhandle));
- h->errinfo_pool = (ErrorInfo_struct *)
- pci_alloc_consistent(h->pdev,
- h->nr_cmds * sizeof(ErrorInfo_struct),
- &(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");
+ if (cciss_allocate_cmd_pool(h))
goto clean4;
- }
/* Need space for temp scatter list */
h->scatter_list = kmalloc(h->max_commands *
@@ -4837,21 +4855,12 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
return 1;
clean4:
- kfree(h->cmd_pool_bits);
+ cciss_free_cmd_pool(h);
/* Free up sg elements */
for (k-- ; k >= 0; k--)
kfree(h->scatter_list[k]);
kfree(h->scatter_list);
cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
- if (h->cmd_pool)
- pci_free_consistent(h->pdev,
- h->nr_cmds * sizeof(CommandList_struct),
- h->cmd_pool, h->cmd_pool_dhandle);
- if (h->errinfo_pool)
- pci_free_consistent(h->pdev,
- h->nr_cmds * sizeof(ErrorInfo_struct),
- h->errinfo_pool,
- h->errinfo_pool_dhandle);
free_irq(h->intr[PERF_MODE_INT], h);
clean2:
unregister_blkdev(h->major, h->devname);
@@ -4949,11 +4958,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
iounmap(h->cfgtable);
iounmap(h->vaddr);
- pci_free_consistent(h->pdev, h->nr_cmds * sizeof(CommandList_struct),
- h->cmd_pool, h->cmd_pool_dhandle);
- pci_free_consistent(h->pdev, h->nr_cmds * sizeof(ErrorInfo_struct),
- h->errinfo_pool, h->errinfo_pool_dhandle);
- kfree(h->cmd_pool_bits);
+ cciss_free_cmd_pool(h);
/* Free up sg elements */
for (j = 0; j < h->nr_cmds; j++)
kfree(h->scatter_list[j]);
next prev parent reply other threads:[~2011-05-03 19:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-03 19:52 [PATCH 00/16] cciss: May 3, 2011 updates Stephen M. Cameron
2011-05-03 19:52 ` [PATCH 01/16] cciss: add readl after writel in interrupt mask setting code Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 02/16] cciss: do a better job of detecting controller reset failure Stephen M. Cameron
2011-05-03 19:53 ` Stephen M. Cameron [this message]
2011-05-03 19:53 ` [PATCH 04/16] cciss: factor out scatterlist allocation functions Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 05/16] cciss: factor out irq request code Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 06/16] cciss: fix reply pool and block fetch table memory leaks Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 07/16] cciss: get rid of message related magic numbers Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 08/16] cciss: increase time to wait for board reset to start Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 09/16] cciss: clarify messages around reset behavior Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 10/16] cciss: increase timeouts for post-reset no-ops Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 11/16] cciss: use new doorbell-bit-5 reset method Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 12/16] cciss: do soft reset if hard reset is broken Stephen M. Cameron
2011-05-03 19:53 ` [PATCH 13/16] cciss: remove superfluous sleeps around reset code Stephen M. Cameron
2011-05-03 19:54 ` [PATCH 14/16] cciss: do not attempt PCI power management reset method if we know it won't work Stephen M. Cameron
2011-05-03 19:54 ` [PATCH 15/16] cciss: do not use bit 2 doorbell reset Stephen M. Cameron
2011-05-03 19:54 ` [PATCH 16/16] cciss: add cciss_tape_cmds module paramter Stephen M. Cameron
2011-05-06 14:29 ` [PATCH 00/16] cciss: May 3, 2011 updates Jens Axboe
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=20110503195305.5154.73383.stgit@beardog.cce.hp.com \
--to=scameron@beardog.cce.hp.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=linux-kernel@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