Patch from: steve cameron <steve.cameron@hp.com>

From randy.dunlap@verizon.net, fix memory leaks in cciss driver



 drivers/block/cciss.c |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)

diff -puN drivers/block/cciss.c~cciss-2 drivers/block/cciss.c
--- 25/drivers/block/cciss.c~cciss-2	Wed Feb 12 12:11:23 2003
+++ 25-akpm/drivers/block/cciss.c	Wed Feb 12 12:11:23 2003
@@ -1013,9 +1013,9 @@ static int register_new_disk(int ctlr)
 	int new_lun_index = 0;
 	int free_index_found = 0;
 	int free_index = 0;
-	ReportLunData_struct *ld_buff;
-	ReadCapdata_struct *size_buff;
-	InquiryData_struct *inq_buff;
+	ReportLunData_struct *ld_buff = NULL;
+	ReadCapdata_struct *size_buff = NULL;
+	InquiryData_struct *inq_buff = NULL;
 	int return_code;
 	int listlength = 0;
 	__u32 lunid = 0;
@@ -1030,26 +1030,14 @@ static int register_new_disk(int ctlr)
 	
 	ld_buff = kmalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
 	if (ld_buff == NULL)
-	{
-		printk(KERN_ERR "cciss: out of memory\n");
-		return -1;
-	}
+		goto mem_msg;
 	memset(ld_buff, 0, sizeof(ReportLunData_struct));
 	size_buff = kmalloc(sizeof( ReadCapdata_struct), GFP_KERNEL);
         if (size_buff == NULL)
-        {
-                printk(KERN_ERR "cciss: out of memory\n");
-		kfree(ld_buff);
-                return -1;
-        }
+		goto mem_msg;
 	inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
         if (inq_buff == NULL)
-        {
-                printk(KERN_ERR "cciss: out of memory\n");
-                kfree(ld_buff);
-		kfree(size_buff);
-                return -1;
-        }
+		goto mem_msg;
 	
 	return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 
 			sizeof(ReportLunData_struct), 0, 0, 0 );
@@ -1068,7 +1056,7 @@ static int register_new_disk(int ctlr)
 		printk(KERN_WARNING "cciss: report logical volume"
 			" command failed\n");
 		listlength = 0;
-		return -1;
+		goto free_err;
 	}
 	num_luns = listlength / 8; // 8 bytes pre entry
 	if (num_luns > CISS_MAX_LUN)
@@ -1119,7 +1107,7 @@ static int register_new_disk(int ctlr)
 	 if (!new_lun_found)
 	 {
 		printk(KERN_WARNING "cciss:  New Logical Volume not found\n");
-		return -1;
+		goto free_err;
 	 }
 	 /* Now find the free index 	*/
 	for(i=0; i <CISS_MAX_LUN; i++)
@@ -1140,7 +1128,7 @@ static int register_new_disk(int ctlr)
 	if (!free_index_found)
 	{
 		printk(KERN_WARNING "cciss: unable to find free slot for disk\n");
-                return -1;
+		goto free_err;
          }
 
 	logvol = free_index;
@@ -1233,11 +1221,16 @@ static int register_new_disk(int ctlr)
         disk = hba[ctlr]->gendisk[logvol];
 	set_capacity(disk, hba[ctlr]->drv[logvol].nr_blocks);
 	add_disk(disk);
-	
+freeret:
 	kfree(ld_buff);
 	kfree(size_buff);
 	kfree(inq_buff);
 	return (logvol);
+mem_msg:
+	printk(KERN_ERR "cciss: out of memory\n");
+free_err:
+	logvol = -1;
+	goto freeret;
 }
 /*
  *   Wait polling for a command to complete.

_