Check the return values of kmalloc()
SVN-Revision: 10599
This commit is contained in:
parent
cb354d2750
commit
6a2a1e251b
1 changed files with 25 additions and 6 deletions
|
@ -158,6 +158,8 @@ static void add_handler(switch_driver *driver, const switch_config *handler, str
|
||||||
|
|
||||||
switch_proc_handler *tmp;
|
switch_proc_handler *tmp;
|
||||||
tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
|
tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
|
||||||
|
if (!tmp)
|
||||||
|
return;
|
||||||
INIT_LIST_HEAD(&tmp->list);
|
INIT_LIST_HEAD(&tmp->list);
|
||||||
tmp->parent = parent;
|
tmp->parent = parent;
|
||||||
tmp->nr = nr;
|
tmp->nr = nr;
|
||||||
|
@ -240,10 +242,25 @@ static int do_register(switch_driver *driver)
|
||||||
int i;
|
int i;
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
if ((priv = kmalloc(sizeof(switch_priv), GFP_KERNEL)) == NULL)
|
priv = kmalloc(sizeof(switch_priv), GFP_KERNEL);
|
||||||
return -ENOBUFS;
|
if (!priv)
|
||||||
|
return -ENOMEM;
|
||||||
driver->data = (void *) priv;
|
driver->data = (void *) priv;
|
||||||
|
|
||||||
|
priv->ports = kmalloc((driver->ports + 1) * sizeof(struct proc_dir_entry *),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!priv->ports) {
|
||||||
|
kfree(priv);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
priv->vlans = kmalloc((driver->vlans + 1) * sizeof(struct proc_dir_entry *),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!priv->vlans) {
|
||||||
|
kfree(priv->ports);
|
||||||
|
kfree(priv);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
INIT_LIST_HEAD(&priv->data.list);
|
INIT_LIST_HEAD(&priv->data.list);
|
||||||
|
|
||||||
priv->nr = drv_num++;
|
priv->nr = drv_num++;
|
||||||
|
@ -254,7 +271,6 @@ static int do_register(switch_driver *driver)
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->port_dir = proc_mkdir("port", priv->driver_dir);
|
priv->port_dir = proc_mkdir("port", priv->driver_dir);
|
||||||
priv->ports = kmalloc((driver->ports + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL);
|
|
||||||
for (i = 0; i < driver->ports; i++) {
|
for (i = 0; i < driver->ports; i++) {
|
||||||
sprintf(buf, "%d", i);
|
sprintf(buf, "%d", i);
|
||||||
priv->ports[i] = proc_mkdir(buf, priv->port_dir);
|
priv->ports[i] = proc_mkdir(buf, priv->port_dir);
|
||||||
|
@ -264,7 +280,6 @@ static int do_register(switch_driver *driver)
|
||||||
priv->ports[i] = NULL;
|
priv->ports[i] = NULL;
|
||||||
|
|
||||||
priv->vlan_dir = proc_mkdir("vlan", priv->driver_dir);
|
priv->vlan_dir = proc_mkdir("vlan", priv->driver_dir);
|
||||||
priv->vlans = kmalloc((driver->vlans + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL);
|
|
||||||
for (i = 0; i < driver->vlans; i++) {
|
for (i = 0; i < driver->vlans; i++) {
|
||||||
sprintf(buf, "%d", i);
|
sprintf(buf, "%d", i);
|
||||||
priv->vlans[i] = proc_mkdir(buf, priv->vlan_dir);
|
priv->vlans[i] = proc_mkdir(buf, priv->vlan_dir);
|
||||||
|
@ -339,6 +354,8 @@ switch_vlan_config *switch_parse_vlan(switch_driver *driver, char *buf)
|
||||||
int j, u, p, s;
|
int j, u, p, s;
|
||||||
|
|
||||||
c = kmalloc(sizeof(switch_vlan_config), GFP_KERNEL);
|
c = kmalloc(sizeof(switch_vlan_config), GFP_KERNEL);
|
||||||
|
if (!c)
|
||||||
|
return NULL;
|
||||||
memset(c, 0, sizeof(switch_vlan_config));
|
memset(c, 0, sizeof(switch_vlan_config));
|
||||||
|
|
||||||
while (isspace(*buf)) buf++;
|
while (isspace(*buf)) buf++;
|
||||||
|
@ -405,6 +422,8 @@ int switch_register_driver(switch_driver *driver)
|
||||||
}
|
}
|
||||||
|
|
||||||
new = kmalloc(sizeof(switch_driver), GFP_KERNEL);
|
new = kmalloc(sizeof(switch_driver), GFP_KERNEL);
|
||||||
|
if (!new)
|
||||||
|
return -ENOMEM;
|
||||||
memcpy(new, driver, sizeof(switch_driver));
|
memcpy(new, driver, sizeof(switch_driver));
|
||||||
new->name = strdup(driver->name);
|
new->name = strdup(driver->name);
|
||||||
new->interface = strdup(driver->interface);
|
new->interface = strdup(driver->interface);
|
||||||
|
|
Loading…
Reference in a new issue