Messages in this thread Patch in this message |  | | | Date | Wed, 9 Aug 2000 12:11:40 -0300 | | From | Arnaldo Carvalho de Melo <> | | Subject | [PATCH] wavelan_cs.c: checking kmallocs in the attach function |
| |
Hi,
Please take a look and consider applying.
- Arnaldo
--- linux-2.4.0-test6-pre9/drivers/net/pcmcia/wavelan_cs.c Thu May 4 15:24:42 2000 +++ linux-2.4.0-test6-pre9.acme/drivers/net/pcmcia/wavelan_cs.c Wed Aug 9 12:07:32 2000 @@ -37,6 +37,12 @@ * Apr 2 '98 made changes to bring the i82593 control/int handling in line * with offical specs... * + * Changes: + * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/09/2000 + * - reorganize kmallocs in wavelan_attach, checking all for failure + * and releasing the previous allocations if one fails + * + * **************************************************************************** * Copyright 1995 * Anthony D. Joseph @@ -4424,7 +4430,27 @@ /* Initialize the dev_link_t structure */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); + + if (!link) + return NULL; + + /* Allocate the generic data structure */ + dev = kmalloc(sizeof(struct net_device), GFP_KERNEL); + + if (!dev) + goto fail_alloc_dev; + + /* Allocate the wavelan-specific data structure. */ + lp = (net_local *) kmalloc(sizeof(net_local), GFP_KERNEL); + + if (!lp) + goto fail_alloc_dev_priv; + + memset(lp, 0, sizeof(net_local)); memset(link, 0, sizeof(struct dev_link_t)); + memset(dev, 0, sizeof(struct net_device)); + + dev->priv = lp; /* Unused for the Wavelan */ link->release.function = &wv_pcmcia_release; @@ -4454,15 +4480,8 @@ link->next = dev_list; dev_list = link; - /* Allocate the generic data structure */ - dev = kmalloc(sizeof(struct net_device), GFP_KERNEL); - memset(dev, 0x00, sizeof(struct net_device)); link->priv = link->irq.Instance = dev; - /* Allocate the wavelan-specific data structure. */ - dev->priv = lp = (net_local *) kmalloc(sizeof(net_local), GFP_KERNEL); - memset(lp, 0x00, sizeof(net_local)); - /* Init specific data */ wv_wait_completed = 0; lp->status = FALSE; @@ -4531,6 +4550,12 @@ #endif return link; + +fail_alloc_dev_priv: + kfree(dev); +fail_alloc_dev: + kfree(link); + return NULL; } /*------------------------------------------------------------------*/ - 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/
|  |