[PATCH] com20020_cs.c: mem leakage fixed

From: Arnaldo Carvalho de Melo (acme@conectiva.com.br)
Date: Tue Aug 08 2000 - 09:59:26 EST


Hi,

     Please take a look and consider applying.

- Arnaldo

--- linux-2.4.0-test6-pre8/drivers/net/pcmcia/com20020_cs.c Fri Jul 28 06:34:44 2000
+++ linux-2.4.0-test6-pre8.acme/drivers/net/pcmcia/com20020_cs.c Tue Aug 8 11:52:46 2000
@@ -21,6 +21,11 @@
  * modified by SRC, incorporated herein by reference.
  *
  * **********************
+ * Changes:
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
+ * - reorganize kmallocs in com20020_attach, checking all for failure
+ * and releasing the previous allocations if one fails
+ * **********************
  *
  * For more details, see drivers/net/arcnet.c
  *
@@ -198,7 +203,24 @@
     link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
     if (!link)
         return NULL;
+
+ info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
+ if (!info)
+ goto fail_alloc_info;
+
+ lp = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
+ if (!lp)
+ goto fail_alloc_lp;
+
+ dev = dev_alloc("arc%d", &ret);
+ if (!dev)
+ goto fail_alloc_dev;
+
+ memset(info, 0, sizeof(struct com20020_dev_t));
+ memset(lp, 0, sizeof(struct arcnet_local));
     memset(link, 0, sizeof(struct dev_link_t));
+ dev->priv = lp;
+
     link->release.function = &com20020_release;
     link->release.data = (u_long)link;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -216,19 +238,6 @@
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.Present = PRESENT_OPTION;
 
- info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
- if (!info)
- return NULL;
- memset(info, 0, sizeof(struct com20020_dev_t));
-
- dev = dev_alloc("arc%d", &ret);
- if (!dev)
- return NULL;
- lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
- if (!lp)
- return NULL;
- memset(lp, 0, sizeof(struct arcnet_local));
-
     /* fill in our module parameters as defaults */
     dev->dev_addr[0] = node;
     lp->timeout = timeout;
@@ -260,6 +269,14 @@
     }
 
     return link;
+
+fail_alloc_dev:
+ kfree(lp);
+fail_alloc_lp:
+ kfree(info);
+fail_alloc_info:
+ kfree(link);
+ return NULL;
 } /* com20020_attach */
 
 /*======================================================================

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 21:00:15 EST