diff options
author | Stephen M. Cameron <scameron@beardog.cce.hp.com> | 2011-05-03 15:53:10 -0400 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2011-05-06 10:23:48 -0400 |
commit | abf7966e616ef6e04393ef3678227f77d6179a8a (patch) | |
tree | 2980bb8819af206b14ebf3cc7d3ed8cab3ccc334 /drivers/block/cciss.c | |
parent | 54dae3432021f38cf20542ccd152dddb91c7c2d7 (diff) |
cciss: factor out scatterlist allocation functions
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'drivers/block/cciss.c')
-rw-r--r-- | drivers/block/cciss.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index 152cb40e2e28..55ca1f45c0c7 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c | |||
@@ -4673,6 +4673,39 @@ static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h) | |||
4673 | return 0; | 4673 | return 0; |
4674 | } | 4674 | } |
4675 | 4675 | ||
4676 | static __devinit int cciss_allocate_scatterlists(ctlr_info_t *h) | ||
4677 | { | ||
4678 | int i; | ||
4679 | |||
4680 | /* zero it, so that on free we need not know how many were alloc'ed */ | ||
4681 | h->scatter_list = kzalloc(h->max_commands * | ||
4682 | sizeof(struct scatterlist *), GFP_KERNEL); | ||
4683 | if (!h->scatter_list) | ||
4684 | return -ENOMEM; | ||
4685 | |||
4686 | for (i = 0; i < h->nr_cmds; i++) { | ||
4687 | h->scatter_list[i] = kmalloc(sizeof(struct scatterlist) * | ||
4688 | h->maxsgentries, GFP_KERNEL); | ||
4689 | if (h->scatter_list[i] == NULL) { | ||
4690 | dev_err(&h->pdev->dev, "could not allocate " | ||
4691 | "s/g lists\n"); | ||
4692 | return -ENOMEM; | ||
4693 | } | ||
4694 | } | ||
4695 | return 0; | ||
4696 | } | ||
4697 | |||
4698 | static void cciss_free_scatterlists(ctlr_info_t *h) | ||
4699 | { | ||
4700 | int i; | ||
4701 | |||
4702 | if (h->scatter_list) { | ||
4703 | for (i = 0; i < h->nr_cmds; i++) | ||
4704 | kfree(h->scatter_list[i]); | ||
4705 | kfree(h->scatter_list); | ||
4706 | } | ||
4707 | } | ||
4708 | |||
4676 | static void cciss_free_cmd_pool(ctlr_info_t *h) | 4709 | static void cciss_free_cmd_pool(ctlr_info_t *h) |
4677 | { | 4710 | { |
4678 | kfree(h->cmd_pool_bits); | 4711 | kfree(h->cmd_pool_bits); |
@@ -4696,7 +4729,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
4696 | { | 4729 | { |
4697 | int i; | 4730 | int i; |
4698 | int j = 0; | 4731 | int j = 0; |
4699 | int k = 0; | ||
4700 | int rc; | 4732 | int rc; |
4701 | int dac, return_code; | 4733 | int dac, return_code; |
4702 | InquiryData_struct *inq_buff; | 4734 | InquiryData_struct *inq_buff; |
@@ -4781,23 +4813,9 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
4781 | if (cciss_allocate_cmd_pool(h)) | 4813 | if (cciss_allocate_cmd_pool(h)) |
4782 | goto clean4; | 4814 | goto clean4; |
4783 | 4815 | ||
4784 | /* Need space for temp scatter list */ | 4816 | if (cciss_allocate_scatterlists(h)) |
4785 | h->scatter_list = kmalloc(h->max_commands * | ||
4786 | sizeof(struct scatterlist *), | ||
4787 | GFP_KERNEL); | ||
4788 | if (!h->scatter_list) | ||
4789 | goto clean4; | 4817 | goto clean4; |
4790 | 4818 | ||
4791 | for (k = 0; k < h->nr_cmds; k++) { | ||
4792 | h->scatter_list[k] = kmalloc(sizeof(struct scatterlist) * | ||
4793 | h->maxsgentries, | ||
4794 | GFP_KERNEL); | ||
4795 | if (h->scatter_list[k] == NULL) { | ||
4796 | dev_err(&h->pdev->dev, | ||
4797 | "could not allocate s/g lists\n"); | ||
4798 | goto clean4; | ||
4799 | } | ||
4800 | } | ||
4801 | h->cmd_sg_list = cciss_allocate_sg_chain_blocks(h, | 4819 | h->cmd_sg_list = cciss_allocate_sg_chain_blocks(h, |
4802 | h->chainsize, h->nr_cmds); | 4820 | h->chainsize, h->nr_cmds); |
4803 | if (!h->cmd_sg_list && h->chainsize > 0) | 4821 | if (!h->cmd_sg_list && h->chainsize > 0) |
@@ -4856,10 +4874,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev, | |||
4856 | 4874 | ||
4857 | clean4: | 4875 | clean4: |
4858 | cciss_free_cmd_pool(h); | 4876 | cciss_free_cmd_pool(h); |
4859 | /* Free up sg elements */ | 4877 | cciss_free_scatterlists(h); |
4860 | for (k-- ; k >= 0; k--) | ||
4861 | kfree(h->scatter_list[k]); | ||
4862 | kfree(h->scatter_list); | ||
4863 | cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); | 4878 | cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); |
4864 | free_irq(h->intr[PERF_MODE_INT], h); | 4879 | free_irq(h->intr[PERF_MODE_INT], h); |
4865 | clean2: | 4880 | clean2: |