Commit b2e68602 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] Memory leak in drivers_net_arlan.c (1)

From:  Pablo Menichini <pablo@menichini.com.ar>
parent b929b515
...@@ -1188,34 +1188,31 @@ static int __init ...@@ -1188,34 +1188,31 @@ static int __init
{ {
struct net_device *dev; struct net_device *dev;
struct arlan_private *ap;
ARLAN_DEBUG_ENTRY("arlan_allocate_device"); ARLAN_DEBUG_ENTRY("arlan_allocate_device");
if (!devs) if (!devs) {
dev = init_etherdev(0, sizeof(struct arlan_private)); dev = init_etherdev(0, sizeof(struct arlan_private) + sizeof(struct arlan_shmem));
else if (!dev) {
{ printk(KERN_ERR "ARLAN: init_etherdev failed\n");
dev = devs;
dev->priv = kmalloc(sizeof(struct arlan_private), GFP_KERNEL);
};
if (dev == NULL || dev->priv == NULL)
{
printk(KERN_CRIT "init_etherdev failed ");
return 0; return 0;
} }
ap = dev->priv;
memset(dev->priv,0,sizeof(struct arlan_private)); ap->config = dev->priv + sizeof(struct arlan_private);
ap->init_etherdev_alloc = 1;
((struct arlan_private *) dev->priv)->conf = } else {
kmalloc(sizeof(struct arlan_shmem), GFP_KERNEL); dev = devs;
dev->priv = kmalloc(sizeof(struct arlan_private) + sizeof(struct arlan_shmem), GFP_KERNEL);
if (dev == NULL || dev->priv == NULL || if (!dev->priv) {
((struct arlan_private *) dev->priv)->conf == NULL) printk(KERN_ERR "ARLAN: kmalloc of dev->priv failed\n");
{
return 0; return 0;
printk(KERN_CRIT " No memory at arlan_allocate_device \n");
} }
ap = dev->priv;
ap->config = dev->priv + sizeof(struct arlan_private);
memset(ap, 0, sizeof(*ap));
}
/* Fill in the 'dev' fields. */ /* Fill in the 'dev' fields. */
dev->base_addr = 0; dev->base_addr = 0;
dev->mem_start = 0; dev->mem_start = 0;
...@@ -2056,6 +2053,7 @@ int init_module(void) ...@@ -2056,6 +2053,7 @@ int init_module(void)
void cleanup_module(void) void cleanup_module(void)
{ {
int i = 0; int i = 0;
struct arlan_private ap;
ARLAN_DEBUG_ENTRY("cleanup_module"); ARLAN_DEBUG_ENTRY("cleanup_module");
...@@ -2069,13 +2067,14 @@ void cleanup_module(void) ...@@ -2069,13 +2067,14 @@ void cleanup_module(void)
// release_mem_region(virt_to_phys(arlan_device[i]->mem_start), 0x2000 ); // release_mem_region(virt_to_phys(arlan_device[i]->mem_start), 0x2000 );
unregister_netdev(arlan_device[i]); unregister_netdev(arlan_device[i]);
if (arlan_device[i]->priv) ap = arlan_device[i]->priv;
{ if (ap->init_etherdev_alloc) {
if (((struct arlan_private *) arlan_device[i]->priv)->conf)
kfree(((struct arlan_private *) arlan_device[i]->priv)->conf);
kfree(arlan_device[i]); kfree(arlan_device[i]);
}
arlan_device[i] = NULL; arlan_device[i] = NULL;
} else {
kfree(ap);
ap = NULL;
}
} }
} }
ARLAN_DEBUG_EXIT("cleanup_module"); ARLAN_DEBUG_EXIT("cleanup_module");
......
...@@ -410,6 +410,7 @@ struct arlan_private { ...@@ -410,6 +410,7 @@ struct arlan_private {
int out_time10; int out_time10;
int in_bytes10; int in_bytes10;
int out_bytes10; int out_bytes10;
int init_etherdev_alloc;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment