public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Rasmus Andersen <rasmus@jaquet.dk>
To: dwmw2@redhat.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] cleanup in drivers/mtd/ftl.c (245-ac16)
Date: Fri, 22 Jun 2001 22:29:31 +0200	[thread overview]
Message-ID: <20010622222931.C842@jaquet.dk> (raw)

Hi.

The patch below adds one instance of vmalloc return code checking
and a number of error path resource release cleanups in build_maps. 
It is against 245-ac16.

(The vmalloc non-check was reported by the Stanford team a
while back.)


--- linux-245-ac16-clean/drivers/mtd/ftl.c	Sun May 27 22:15:23 2001
+++ linux-245-ac16/drivers/mtd/ftl.c	Fri Jun 22 22:24:09 2001
@@ -313,6 +313,7 @@
     ssize_t retval;
     loff_t offset;
 
+    ret = -1;
     /* Set up erase unit maps */
     part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) -
 	part->header.NumTransferUnits;
@@ -324,7 +325,8 @@
     part->XferInfo =
 	kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t),
 		GFP_KERNEL);
-    if (!part->XferInfo) return -1;
+    if (!part->XferInfo) 
+	    goto err_free_EUInfo;
 
     xvalid = xtrans = 0;
     for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) {
@@ -334,8 +336,9 @@
 			      (unsigned char *)&header);
 	
 	if (ret) 
-	    return ret;
+	    goto err_free_XferInfo;
 
+	ret = -1;
 	/* Is this a transfer partition? */
 	hdr_ok = (strcmp(header.DataOrgTuple+3, "FTL100") == 0);
 	if (hdr_ok && (le16_to_cpu(header.LogicalEUN) < part->DataUnits) &&
@@ -348,7 +351,7 @@
 	    if (xtrans == part->header.NumTransferUnits) {
 		printk(KERN_NOTICE "ftl_cs: format error: too many "
 		       "transfer units!\n");
-		return -1;
+		goto err_free_XferInfo;
 	    }
 	    if (hdr_ok && (le16_to_cpu(header.LogicalEUN) == 0xffff)) {
 		part->XferInfo[xtrans].state = XFER_PREPARED;
@@ -369,18 +372,21 @@
 	(xvalid+xtrans != le16_to_cpu(header.NumEraseUnits))) {
 	printk(KERN_NOTICE "ftl_cs: format error: erase units "
 	       "don't add up!\n");
-	return -1;
+	goto err_free_XferInfo;
     }
     
     /* Set up virtual page map */
     blocks = le32_to_cpu(header.FormattedSize) >> header.BlockSize;
     part->VirtualBlockMap = vmalloc(blocks * sizeof(u_int32_t));
+    if (!part->VirtualBlockMap)
+	    goto err_free_XferInfo;
     memset(part->VirtualBlockMap, 0xff, blocks * sizeof(u_int32_t));
     part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize;
 
     part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(u_int32_t),
 			      GFP_KERNEL);
-    if (!part->bam_cache) return -1;
+    if (!part->bam_cache) 
+	    goto err_free_VirtualBlockMap;
 
     part->bam_index = 0xffff;
     part->FreeTotal = 0;
@@ -395,7 +401,7 @@
 			      (unsigned char *)part->bam_cache);
 	
 	if (ret) 
-	    return ret;
+	    goto err_free_bam_cache;
 
 	for (j = 0; j < part->BlocksPerUnit; j++) {
 	    if (BLOCK_FREE(le32_to_cpu(part->bam_cache[j]))) {
@@ -411,7 +417,17 @@
     }
     
     return 0;
-    
+
+err_free_bam_cache:
+    kfree(part->bam_cache);
+err_free_VirtualBlockMap:
+    vfree(part->VirtualBlockMap);
+err_free_XferInfo:
+    kfree(part->XferInfo);
+err_free_EUInfo:
+    kfree(part->EUNInfo);
+    printk(KERN_ERR "ftl_cs: Out of memory.");
+    return ret;
 } /* build_maps */
 
 /*======================================================================

-- 
Regards,
        Rasmus(rasmus@jaquet.dk)

Open Source. Closed Minds. We are Slashdot. 
  --Anonymous Coward

             reply	other threads:[~2001-06-22 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-22 20:29 Rasmus Andersen [this message]
2001-06-22 20:21 ` [PATCH] cleanup in drivers/mtd/ftl.c (245-ac16) Arnaldo Carvalho de Melo
2001-06-22 20:57   ` Rasmus Andersen

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=20010622222931.C842@jaquet.dk \
    --to=rasmus@jaquet.dk \
    --cc=dwmw2@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.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