@@ -4673,6 +4673,39 @@ static __devinit int cciss_allocate_cmd_pool(ctlr_info_t *h)
46734673 return 0 ;
46744674}
46754675
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+
46764709static void cciss_free_cmd_pool (ctlr_info_t * h )
46774710{
46784711 kfree (h -> cmd_pool_bits );
@@ -4696,7 +4729,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
46964729{
46974730 int i ;
46984731 int j = 0 ;
4699- int k = 0 ;
47004732 int rc ;
47014733 int dac , return_code ;
47024734 InquiryData_struct * inq_buff ;
@@ -4781,23 +4813,9 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
47814813 if (cciss_allocate_cmd_pool (h ))
47824814 goto clean4 ;
47834815
4784- /* Need space for temp scatter list */
4785- h -> scatter_list = kmalloc (h -> max_commands *
4786- sizeof (struct scatterlist * ),
4787- GFP_KERNEL );
4788- if (!h -> scatter_list )
4816+ if (cciss_allocate_scatterlists (h ))
47894817 goto clean4 ;
47904818
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- }
48014819 h -> cmd_sg_list = cciss_allocate_sg_chain_blocks (h ,
48024820 h -> chainsize , h -> nr_cmds );
48034821 if (!h -> cmd_sg_list && h -> chainsize > 0 )
@@ -4856,10 +4874,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
48564874
48574875clean4 :
48584876 cciss_free_cmd_pool (h );
4859- /* Free up sg elements */
4860- for (k -- ; k >= 0 ; k -- )
4861- kfree (h -> scatter_list [k ]);
4862- kfree (h -> scatter_list );
4877+ cciss_free_scatterlists (h );
48634878 cciss_free_sg_chain_blocks (h -> cmd_sg_list , h -> nr_cmds );
48644879 free_irq (h -> intr [PERF_MODE_INT ], h );
48654880clean2 :
0 commit comments