mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Om Narasimhan" <om.turyx@gmail.com>
To: linux-kernel@vger.kernel.org, kernel-janitors@lists.osdl.org
Subject: removing multiple kfree() and return's
Date: Thu, 21 Sep 2006 23:16:51 -0700	[thread overview]
Message-ID: <6b4e42d10609212316td429f66q51e35d80c823c571@mail.gmail.com> (raw)

Removes repeated calls to kfree() and return; by introducing a label
and goto label.

Signed off by : Om Narasimhan <om.turyx@gmail.com>


 drivers/block/cpqarray.c |   62 +++++++++++++++-------------------------------
 1 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 78082ed..e167cec 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -1642,58 +1642,47 @@ static void start_fwbk(int ctlr)
     It is used only at init time.
 *****************************************************************/
 static void getgeometry(int ctlr)
-{				
-	id_log_drv_t *id_ldrive;
-	id_ctlr_t *id_ctlr_buf;
-	sense_log_drv_stat_t *id_lstatus_buf;
-	config_t *sense_config_buf;
+{
+	id_log_drv_t *id_ldrive = NULL;
+	id_ctlr_t *id_ctlr_buf = NULL;
+	sense_log_drv_stat_t *id_lstatus_buf = NULL;
+	config_t *sense_config_buf = NULL;
 	unsigned int log_unit, log_index;
 	int ret_code, size;
-	drv_info_t *drv;
+	drv_info_t *drv = NULL;
 	ctlr_info_t *info_p = hba[ctlr];
 	int i;

 	info_p->log_drv_map = 0;	
 	
-	id_ldrive = (id_log_drv_t *)kmalloc(sizeof(id_log_drv_t), GFP_KERNEL);
+	id_ldrive = (id_log_drv_t *)kzalloc(sizeof(id_log_drv_t), GFP_KERNEL);
 	if(id_ldrive == NULL)
 	{
 		printk( KERN_ERR "cpqarray:  out of memory.\n");
-		return;
+		goto end;
 	}

-	id_ctlr_buf = (id_ctlr_t *)kmalloc(sizeof(id_ctlr_t), GFP_KERNEL);
+	id_ctlr_buf = (id_ctlr_t *)kzalloc(sizeof(id_ctlr_t), GFP_KERNEL);
 	if(id_ctlr_buf == NULL)
 	{
-		kfree(id_ldrive);
 		printk( KERN_ERR "cpqarray:  out of memory.\n");
-		return;
+		goto end;
 	}

-	id_lstatus_buf = (sense_log_drv_stat_t
*)kmalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL);
+	id_lstatus_buf = (sense_log_drv_stat_t
*)kzalloc(sizeof(sense_log_drv_stat_t), GFP_KERNEL);
 	if(id_lstatus_buf == NULL)
 	{
-		kfree(id_ctlr_buf);
-		kfree(id_ldrive);
 		printk( KERN_ERR "cpqarray:  out of memory.\n");
-		return;
+		goto end;
 	}

-	sense_config_buf = (config_t *)kmalloc(sizeof(config_t), GFP_KERNEL);
+	sense_config_buf = (config_t *)kzalloc(sizeof(config_t), GFP_KERNEL);
 	if(sense_config_buf == NULL)
 	{
-		kfree(id_lstatus_buf);
-		kfree(id_ctlr_buf);
-		kfree(id_ldrive);
 		printk( KERN_ERR "cpqarray:  out of memory.\n");
-		return;
+		goto end;
 	}

-	memset(id_ldrive, 0, sizeof(id_log_drv_t));
-	memset(id_ctlr_buf, 0, sizeof(id_ctlr_t));
-	memset(id_lstatus_buf, 0, sizeof(sense_log_drv_stat_t));
-	memset(sense_config_buf, 0, sizeof(config_t));
-
 	info_p->phys_drives = 0;
 	info_p->log_drv_map = 0;
 	info_p->drv_assign_map = 0;
@@ -1709,11 +1698,7 @@ static void getgeometry(int ctlr)
 		 */
 		 /* Free all the buffers and return */
 		printk(KERN_ERR "cpqarray: error sending ID controller\n");
-		kfree(sense_config_buf);
-                kfree(id_lstatus_buf);
-                kfree(id_ctlr_buf);
-                kfree(id_ldrive);
-                return;
+		goto end;
         }

 	info_p->log_drives = id_ctlr_buf->nr_drvs;
@@ -1760,11 +1745,7 @@ static void getgeometry(int ctlr)
 			 "Access to this controller has been disabled\n",
 				ctlr, log_unit);
 			/* Free all the buffers and return */
-                	kfree(sense_config_buf);
-                	kfree(id_lstatus_buf);
-                	kfree(id_ctlr_buf);
-                	kfree(id_ldrive);
-                	return;
+			goto end;
 		}
 		/*
 		   Make sure the logical drive is configured
@@ -1795,11 +1776,7 @@ static void getgeometry(int ctlr)
 					info_p->log_drv_map = 0;
 					/* Free all the buffers and return */
                 			printk(KERN_ERR "cpqarray: error sending sense config\n");
-                			kfree(sense_config_buf);
-                			kfree(id_lstatus_buf);
-                			kfree(id_ctlr_buf);
-                			kfree(id_ldrive);
-                			return;
+					goto end;

 				}

@@ -1815,9 +1792,10 @@ static void getgeometry(int ctlr)
 			log_index = log_index + 1;
 		}		/* end of if logical drive configured */
 	}			/* end of for log_unit */
+end:
 	kfree(sense_config_buf);
-  	kfree(id_ldrive);
-  	kfree(id_lstatus_buf);
+	kfree(id_ldrive);
+	kfree(id_lstatus_buf);
 	kfree(id_ctlr_buf);
 	return;

                 reply	other threads:[~2006-09-22  6:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b4e42d10609212316td429f66q51e35d80c823c571@mail.gmail.com \
    --to=om.turyx@gmail.com \
    --cc=kernel-janitors@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®