X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/3814202702cc6ab529c1a0977ea5615c87ce48a8..c291b847846f5921d669b17478cbf59f0c83ee19:/package/switch/src/switch-core.c?ds=inline diff --git a/package/switch/src/switch-core.c b/package/switch/src/switch-core.c index e0aa541f4..c34386b76 100644 --- a/package/switch/src/switch-core.c +++ b/package/switch/src/switch-core.c @@ -158,6 +158,8 @@ static void add_handler(switch_driver *driver, const switch_config *handler, str switch_proc_handler *tmp; tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL); + if (!tmp) + return; INIT_LIST_HEAD(&tmp->list); tmp->parent = parent; tmp->nr = nr; @@ -239,11 +241,26 @@ static int do_register(switch_driver *driver) switch_priv *priv; int i; char buf[4]; - - if ((priv = kmalloc(sizeof(switch_priv), GFP_KERNEL)) == NULL) - return -ENOBUFS; + + priv = kmalloc(sizeof(switch_priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; 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); 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->ports = kmalloc((driver->ports + 1) * sizeof(struct proc_dir_entry *), GFP_KERNEL); for (i = 0; i < driver->ports; i++) { sprintf(buf, "%d", i); 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->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++) { sprintf(buf, "%d", i); 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; c = kmalloc(sizeof(switch_vlan_config), GFP_KERNEL); + if (!c) + return NULL; memset(c, 0, sizeof(switch_vlan_config)); while (isspace(*buf)) buf++; @@ -387,12 +404,27 @@ switch_vlan_config *switch_parse_vlan(switch_driver *driver, char *buf) } +int switch_device_registered (char* device) { + struct list_head *pos; + switch_driver *new; + + list_for_each(pos, &drivers.list) { + if (strcmp(list_entry(pos, switch_driver, list)->interface, device) == 0) { + printk("There is already a switch registered on the device '%s'\n", device); + return -EINVAL; + } + } + + return 0; +} + + int switch_register_driver(switch_driver *driver) { struct list_head *pos; switch_driver *new; int ret; - + list_for_each(pos, &drivers.list) { if (strcmp(list_entry(pos, switch_driver, list)->name, driver->name) == 0) { printk("Switch driver '%s' already exists in the kernel\n", driver->name); @@ -405,6 +437,8 @@ int switch_register_driver(switch_driver *driver) } new = kmalloc(sizeof(switch_driver), GFP_KERNEL); + if (!new) + return -ENOMEM; memcpy(new, driver, sizeof(switch_driver)); new->name = strdup(driver->name); new->interface = strdup(driver->interface); @@ -457,6 +491,7 @@ static void __exit switch_exit(void) MODULE_AUTHOR("Felix Fietkau "); MODULE_LICENSE("GPL"); +EXPORT_SYMBOL(switch_device_registered); EXPORT_SYMBOL(switch_register_driver); EXPORT_SYMBOL(switch_unregister_driver); EXPORT_SYMBOL(switch_parse_vlan);