Commit b03ac92e authored by Randy Dunlap's avatar Randy Dunlap Committed by Jeff Garzik

[PATCH] reduce stack usage in wanrouter

From Jorn Engel <joern@wohnheim.fh-wedel.de> and Randy Dunlap.

It reduces stack usage in the WAN router by about 0x500 bytes
(from 0x520 to 0x24 when I did it in April).
parent 1158633b
...@@ -668,7 +668,7 @@ static int wanrouter_device_stat(struct wan_device *wandev, ...@@ -668,7 +668,7 @@ static int wanrouter_device_stat(struct wan_device *wandev,
static int wanrouter_device_new_if(struct wan_device *wandev, static int wanrouter_device_new_if(struct wan_device *wandev,
wanif_conf_t *u_conf) wanif_conf_t *u_conf)
{ {
wanif_conf_t conf; wanif_conf_t *cnf;
struct net_device *dev = NULL; struct net_device *dev = NULL;
#ifdef CONFIG_WANPIPE_MULTPPP #ifdef CONFIG_WANPIPE_MULTPPP
struct ppp_device *pppdev=NULL; struct ppp_device *pppdev=NULL;
...@@ -678,38 +678,47 @@ static int wanrouter_device_new_if(struct wan_device *wandev, ...@@ -678,38 +678,47 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
if ((wandev->state == WAN_UNCONFIGURED) || (wandev->new_if == NULL)) if ((wandev->state == WAN_UNCONFIGURED) || (wandev->new_if == NULL))
return -ENODEV; return -ENODEV;
if (copy_from_user(&conf, u_conf, sizeof(wanif_conf_t))) cnf = kmalloc(sizeof(wanif_conf_t), GFP_KERNEL);
return -EFAULT; if (!cnf)
return -ENOBUFS;
if (conf.magic != ROUTER_MAGIC) err = -EFAULT;
return -EINVAL; if (copy_from_user(cnf, u_conf, sizeof(wanif_conf_t)))
goto out;
err = -EINVAL;
if (cnf->magic != ROUTER_MAGIC)
goto out;
if (conf.config_id == WANCONFIG_MPPP) { if (cnf->config_id == WANCONFIG_MPPP) {
#ifdef CONFIG_WANPIPE_MULTPPP #ifdef CONFIG_WANPIPE_MULTPPP
pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL); pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
err = -ENOBUFS;
if (pppdev == NULL) if (pppdev == NULL)
return -ENOBUFS; goto out;
memset(pppdev, 0, sizeof(struct ppp_device)); memset(pppdev, 0, sizeof(struct ppp_device));
pppdev->dev = kmalloc(sizeof(struct net_device), GFP_KERNEL); pppdev->dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
if (pppdev->dev == NULL) { if (pppdev->dev == NULL) {
kfree(pppdev); kfree(pppdev);
return -ENOBUFS; err = -ENOBUFS;
goto out;
} }
memset(pppdev->dev, 0, sizeof(struct net_device)); memset(pppdev->dev, 0, sizeof(struct net_device));
err = wandev->new_if(wandev, err = wandev->new_if(wandev, (struct net_device *)pppdev, cnf);
(struct net_device *)pppdev, &conf);
dev = pppdev->dev; dev = pppdev->dev;
#else #else
printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n", printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n",
wandev->name); wandev->name);
return -EPROTONOSUPPORT; err = -EPROTONOSUPPORT;
goto out;
#endif #endif
} else { } else {
dev = kmalloc(sizeof(struct net_device), GFP_KERNEL); dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
err = -ENOBUFS;
if (dev == NULL) if (dev == NULL)
return -ENOBUFS; goto out;
memset(dev, 0, sizeof(struct net_device)); memset(dev, 0, sizeof(struct net_device));
err = wandev->new_if(wandev, dev, &conf); err = wandev->new_if(wandev, dev, cnf);
} }
if (!err) { if (!err) {
...@@ -748,7 +757,8 @@ static int wanrouter_device_new_if(struct wan_device *wandev, ...@@ -748,7 +757,8 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
++wandev->ndev; ++wandev->ndev;
unlock_adapter_irq(&wandev->lock, &smp_flags); unlock_adapter_irq(&wandev->lock, &smp_flags);
return 0; /* done !!! */ err = 0; /* done !!! */
goto out;
} }
} }
if (wandev->del_if) if (wandev->del_if)
...@@ -761,18 +771,19 @@ static int wanrouter_device_new_if(struct wan_device *wandev, ...@@ -761,18 +771,19 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
dev->priv = NULL; dev->priv = NULL;
} }
#ifdef CONFIG_WANPIPE_MULTPPP #ifdef CONFIG_WANPIPE_MULTPPP
if (conf.config_id == WANCONFIG_MPPP) if (cnf->config_id == WANCONFIG_MPPP)
kfree(pppdev); kfree(pppdev);
else else
kfree(dev); kfree(dev);
#else #else
/* Sync PPP is disabled */ /* Sync PPP is disabled */
if (conf.config_id != WANCONFIG_MPPP) if (cnf->config_id != WANCONFIG_MPPP)
kfree(dev); kfree(dev);
#endif #endif
out:
kfree(cnf);
return err; return err;
} }
......
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