Messages in this thread | | | Date | Thu, 10 Aug 2000 12:21:45 -0300 | From | Arnaldo Carvalho de Melo <> | Subject | Re: PCMCIA netdriver crap extractor |
| |
Ok, this is a proof of concept, maybe I'm nitpicking, but...
Em Thu, Aug 10, 2000 at 01:18:19AM +0000, Elmer Joandi escreveu: > static dev_link_t *DRIVER_NAME##_attach(void) \ > { \ > client_reg_t client_reg; \ > dev_link_t *link = NULL; \ > struct net_device *dev = NULL; \ > int ret; \ > \ > PC_DEBUG(0, "DRIVER_NAME##_attach()\n"); \ > flush_stale_links(); \ > \ > \ > link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); \ > memset(link, 0, sizeof(struct dev_link_t)); \ > link->dev = kmalloc(sizeof(struct dev_node_t), GFP_KERNEL); \ > memset(link->dev, 0, sizeof(struct dev_node_t)); \
check resource allocation before using it
> \ > PCMCIA_NETDRIVER_LINK_INIT \ > \ > dev = kmalloc(sizeof(struct net_device ), GFP_KERNEL); \ > memset(dev,0,sizeof(struct net_device)); \ > \ > if (!dev ) { \ > printk(KERN_CRIT "out of mem on dev alloc \n"); \ > kfree(link->dev); \ > kfree(link); \ > return NULL; \ > }; \
and above a common problem I'm finding in the drivers and that I'm trying to fix: try to allocate, _use it_, test to see if the allocation was successful
<snip>
> dev->priv = kmalloc(sizeof(struct DRIVER_NAME##_private), GFP_KERNEL); \ > if (!dev->priv ) {printk(KERN_CRIT "out of mem on dev priv alloc \n"); return NULL;};\ > memset(dev->priv,0,sizeof(struct DRIVER_NAME##_private)); \
above another error: not releasing the previously allocated resources when something fails. Hey, <teasing>here we could use some gotos!</teasing> :)
<snip>
- Arnaldo
- 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/
| |