aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/cciss.c
diff options
context:
space:
mode:
authorStephen M. Cameron <scameron@beardog.cce.hp.com>2011-05-03 15:53:05 -0400
committerJens Axboe <jaxboe@fusionio.com>2011-05-06 10:23:47 -0400
commit54dae3432021f38cf20542ccd152dddb91c7c2d7 (patch)
tree71cef672100c206d2d0108ff6c965c0690c10845 /drivers/block/cciss.c
parent62710ae1ceb839de1eebb5b4492ec8a7fbcf8d02 (diff)
cciss: factor out command pool 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.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index ed6aa83d86dd..152cb40e2e28 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)
4653 return 0; 4653 return 0;
4654} 4654}
4655 4655
4656static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h)
4657{
4658 h->cmd_pool_bits = kmalloc(
4659 DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) *
4660 sizeof(unsigned long), GFP_KERNEL);
4661 h->cmd_pool = pci_alloc_consistent(h->pdev,
4662 h->nr_cmds * sizeof(CommandList_struct),
4663 &(h->cmd_pool_dhandle));
4664 h->errinfo_pool = pci_alloc_consistent(h->pdev,
4665 h->nr_cmds * sizeof(ErrorInfo_struct),
4666 &(h->errinfo_pool_dhandle));
4667 if ((h->cmd_pool_bits == NULL)
4668 || (h->cmd_pool == NULL)
4669 || (h->errinfo_pool == NULL)) {
4670 dev_err(&h->pdev->dev, "out of memory");
4671 return -ENOMEM;
4672 }
4673 return 0;
4674}
4675
4676static void cciss_free_cmd_pool(ctlr_info_t *h)
4677{
4678 kfree(h->cmd_pool_bits);
4679 if (h->cmd_pool)
4680 pci_free_consistent(h->pdev,
4681 h->nr_cmds * sizeof(CommandList_struct),
4682 h->cmd_pool, h->cmd_pool_dhandle);
4683 if (h->errinfo_pool)
4684 pci_free_consistent(h->pdev,
4685 h->nr_cmds * sizeof(ErrorInfo_struct),
4686 h->errinfo_pool, h->errinfo_pool_dhandle);
4687}
4688
4656/* 4689/*
4657 * This is it. Find all the controllers and register them. I really hate 4690 * This is it. Find all the controllers and register them. I really hate
4658 * stealing all these major device numbers. 4691 * stealing all these major device numbers.
@@ -4745,23 +4778,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4745 h->devname, pdev->device, pci_name(pdev), 4778 h->devname, pdev->device, pci_name(pdev),
4746 h->intr[PERF_MODE_INT], dac ? "" : " not"); 4779 h->intr[PERF_MODE_INT], dac ? "" : " not");
4747 4780
4748 h->cmd_pool_bits = 4781 if (cciss_allocate_cmd_pool(h))
4749 kmalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4750 * sizeof(unsigned long), GFP_KERNEL);
4751 h->cmd_pool = (CommandList_struct *)
4752 pci_alloc_consistent(h->pdev,
4753 h->nr_cmds * sizeof(CommandList_struct),
4754 &(h->cmd_pool_dhandle));
4755 h->errinfo_pool = (ErrorInfo_struct *)
4756 pci_alloc_consistent(h->pdev,
4757 h->nr_cmds * sizeof(ErrorInfo_struct),
4758 &(h->errinfo_pool_dhandle));
4759 if ((h->cmd_pool_bits == NULL)
4760 || (h->cmd_pool == NULL)
4761 || (h->errinfo_pool == NULL)) {
4762 dev_err(&h->pdev->dev, "out of memory");
4763 goto clean4; 4782 goto clean4;
4764 }
4765 4783
4766 /* Need space for temp scatter list */ 4784 /* Need space for temp scatter list */
4767 h->scatter_list = kmalloc(h->max_commands * 4785 h->scatter_list = kmalloc(h->max_commands *
@@ -4837,21 +4855,12 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4837 return 1; 4855 return 1;
4838 4856
4839clean4: 4857clean4:
4840 kfree(h->cmd_pool_bits); 4858 cciss_free_cmd_pool(h);
4841 /* Free up sg elements */ 4859 /* Free up sg elements */
4842 for (k-- ; k >= 0; k--) 4860 for (k-- ; k >= 0; k--)
4843 kfree(h->scatter_list[k]); 4861 kfree(h->scatter_list[k]);
4844 kfree(h->scatter_list); 4862 kfree(h->scatter_list);
4845 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); 4863 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4846 if (h->cmd_pool)
4847 pci_free_consistent(h->pdev,
4848 h->nr_cmds * sizeof(CommandList_struct),
4849 h->cmd_pool, h->cmd_pool_dhandle);
4850 if (h->errinfo_pool)
4851 pci_free_consistent(h->pdev,
4852 h->nr_cmds * sizeof(ErrorInfo_struct),
4853 h->errinfo_pool,
4854 h->errinfo_pool_dhandle);
4855 free_irq(h->intr[PERF_MODE_INT], h); 4864 free_irq(h->intr[PERF_MODE_INT], h);
4856clean2: 4865clean2:
4857 unregister_blkdev(h->major, h->devname); 4866 unregister_blkdev(h->major, h->devname);
@@ -4949,11 +4958,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4949 iounmap(h->cfgtable); 4958 iounmap(h->cfgtable);
4950 iounmap(h->vaddr); 4959 iounmap(h->vaddr);
4951 4960
4952 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(CommandList_struct), 4961 cciss_free_cmd_pool(h);
4953 h->cmd_pool, h->cmd_pool_dhandle);
4954 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(ErrorInfo_struct),
4955 h->errinfo_pool, h->errinfo_pool_dhandle);
4956 kfree(h->cmd_pool_bits);
4957 /* Free up sg elements */ 4962 /* Free up sg elements */
4958 for (j = 0; j < h->nr_cmds; j++) 4963 for (j = 0; j < h->nr_cmds; j++)
4959 kfree(h->scatter_list[j]); 4964 kfree(h->scatter_list[j]);