patch_name: wan-stack.patch patch_version: 2003-04-02.20:59:49 author: Randy.Dunlap description: reduce stack in net/wanrouter/wanmain.c::device_new_if() from 0x520 to 0x24; product: Linux product_versions: 2.5.66 changelog: allocate and free the data; maintainer: Gideon Hack (no email address listed) diffstat: = net/wanrouter/wanmain.c | 52 +++++++++++++++++++++++++++++++----------------- 1 files changed, 34 insertions(+), 18 deletions(-) diff -Naur ./net/wanrouter/wanmain.c%WANSTK ./net/wanrouter/wanmain.c --- ./net/wanrouter/wanmain.c%WANSTK 2003-03-24 14:01:11.000000000 -0800 +++ ./net/wanrouter/wanmain.c 2003-04-02 20:49:58.000000000 -0800 @@ -660,7 +660,7 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) { - wanif_conf_t conf; + wanif_conf_t *cnf; netdevice_t *dev=NULL; #ifdef CONFIG_WANPIPE_MULTPPP struct ppp_device *pppdev=NULL; @@ -670,37 +670,51 @@ if ((wandev->state == WAN_UNCONFIGURED) || (wandev->new_if == NULL)) return -ENODEV; - if (copy_from_user(&conf, u_conf, sizeof(wanif_conf_t))) - return -EFAULT; + cnf = kmalloc(sizeof(wanif_conf_t), GFP_KERNEL); + if (!cnf) + return -ENOBUFS; + + if (copy_from_user(cnf, u_conf, sizeof(wanif_conf_t))) { + err = -EFAULT; + goto conffree; + } - if (conf.magic != ROUTER_MAGIC) - return -EINVAL; + if (cnf->magic != ROUTER_MAGIC) { + err = -EINVAL; + goto conffree; + } - if (conf.config_id == WANCONFIG_MPPP) { + if (cnf->config_id == WANCONFIG_MPPP) { #ifdef CONFIG_WANPIPE_MULTPPP pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL); - if (pppdev == NULL) - return -ENOBUFS; + if (pppdev == NULL) { + err = -ENOBUFS; + goto conffree; + } memset(pppdev, 0, sizeof(struct ppp_device)); pppdev->dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL); if (pppdev->dev == NULL) { kfree(pppdev); - return -ENOBUFS; + err = -ENOBUFS; + goto conffree; } memset(pppdev->dev, 0, sizeof(netdevice_t)); - err = wandev->new_if(wandev, (netdevice_t *)pppdev, &conf); + err = wandev->new_if(wandev, (netdevice_t *)pppdev, cnf); dev = pppdev->dev; #else printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n", wandev->name); - return -EPROTONOSUPPORT; + err = -EPROTONOSUPPORT; + goto conffree; #endif } else { dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL); - if (dev == NULL) - return -ENOBUFS; + if (dev == NULL) { + err = -ENOBUFS; + goto conffree; + } memset(dev, 0, sizeof(netdevice_t)); - err = wandev->new_if(wandev, dev, &conf); + err = wandev->new_if(wandev, dev, cnf); } if (!err) { @@ -739,7 +753,8 @@ ++wandev->ndev; unlock_adapter_irq(&wandev->lock, &smp_flags); - return 0; /* done !!! */ + err = 0; /* done !!! */ + goto conffree; } } if (wandev->del_if) @@ -752,18 +767,19 @@ dev->priv = NULL; } - #ifdef CONFIG_WANPIPE_MULTPPP - if (conf.config_id == WANCONFIG_MPPP) + if (cnf->config_id == WANCONFIG_MPPP) kfree(pppdev); else kfree(dev); #else /* Sync PPP is disabled */ - if (conf.config_id != WANCONFIG_MPPP) + if (cnf->config_id != WANCONFIG_MPPP) kfree(dev); #endif + conffree: + kfree(cnf); return err; }