@@ -4653,6 +4653,39 @@ static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
46534653 return 0 ;
46544654}
46554655
4656+ static __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+
4676+ static 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+
46564689/*
46574690 * This is it. Find all the controllers and register them. I really hate
46584691 * stealing all these major device numbers.
@@ -4745,23 +4778,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
47454778 h -> devname , pdev -> device , pci_name (pdev ),
47464779 h -> intr [PERF_MODE_INT ], dac ? "" : " not" );
47474780
4748- h -> cmd_pool_bits =
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" );
4781+ if (cciss_allocate_cmd_pool (h ))
47634782 goto clean4 ;
4764- }
47654783
47664784 /* Need space for temp scatter list */
47674785 h -> scatter_list = kmalloc (h -> max_commands *
@@ -4837,21 +4855,12 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
48374855 return 1 ;
48384856
48394857clean4 :
4840- kfree ( h -> cmd_pool_bits );
4858+ cciss_free_cmd_pool ( h );
48414859 /* Free up sg elements */
48424860 for (k -- ; k >= 0 ; k -- )
48434861 kfree (h -> scatter_list [k ]);
48444862 kfree (h -> scatter_list );
48454863 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 );
48554864 free_irq (h -> intr [PERF_MODE_INT ], h );
48564865clean2 :
48574866 unregister_blkdev (h -> major , h -> devname );
@@ -4949,11 +4958,7 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
49494958 iounmap (h -> cfgtable );
49504959 iounmap (h -> vaddr );
49514960
4952- pci_free_consistent (h -> pdev , h -> nr_cmds * sizeof (CommandList_struct ),
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 );
4961+ cciss_free_cmd_pool (h );
49574962 /* Free up sg elements */
49584963 for (j = 0 ; j < h -> nr_cmds ; j ++ )
49594964 kfree (h -> scatter_list [j ]);
0 commit comments