Commit d65b155e authored by Alexander Viro's avatar Alexander Viro Committed by Stephen Hemminger

[netdrvr ppp] netdev dynamic alloc; convert ppp_net_init to alloc_netdev setup function

parent 5d572ab0
...@@ -917,19 +917,14 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -917,19 +917,14 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
return err; return err;
} }
static int static void ppp_setup(struct net_device *dev)
ppp_net_init(struct net_device *dev)
{ {
dev->hard_header_len = PPP_HDRLEN; dev->hard_header_len = PPP_HDRLEN;
dev->mtu = PPP_MTU; dev->mtu = PPP_MTU;
dev->hard_start_xmit = ppp_start_xmit;
dev->get_stats = ppp_net_stats;
dev->do_ioctl = ppp_net_ioctl;
dev->addr_len = 0; dev->addr_len = 0;
dev->tx_queue_len = 3; dev->tx_queue_len = 3;
dev->type = ARPHRD_PPP; dev->type = ARPHRD_PPP;
dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
return 0;
} }
/* /*
...@@ -2272,23 +2267,13 @@ ppp_create_interface(int unit, int *retp) ...@@ -2272,23 +2267,13 @@ ppp_create_interface(int unit, int *retp)
int i; int i;
ppp = kmalloc(sizeof(struct ppp), GFP_KERNEL); ppp = kmalloc(sizeof(struct ppp), GFP_KERNEL);
if (ppp == 0) if (!ppp)
goto err; goto out;
dev = kmalloc(sizeof(struct net_device), GFP_KERNEL); dev = alloc_netdev(0, "", ppp_setup);
if (dev == 0) if (!dev)
goto err; goto out1;
memset(ppp, 0, sizeof(struct ppp)); memset(ppp, 0, sizeof(struct ppp));
memset(dev, 0, sizeof(struct net_device));
ret = -EEXIST;
down(&all_ppp_sem);
if (unit < 0)
unit = cardmap_find_first_free(all_ppp_units);
else if (cardmap_get(all_ppp_units, unit) != NULL)
goto err_unlock; /* unit already exists */
/* Initialize the new ppp unit */
ppp->file.index = unit;
ppp->mru = PPP_MRU; ppp->mru = PPP_MRU;
init_ppp_file(&ppp->file, INTERFACE); init_ppp_file(&ppp->file, INTERFACE);
ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */ ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
...@@ -2301,20 +2286,29 @@ ppp_create_interface(int unit, int *retp) ...@@ -2301,20 +2286,29 @@ ppp_create_interface(int unit, int *retp)
ppp->minseq = -1; ppp->minseq = -1;
skb_queue_head_init(&ppp->mrq); skb_queue_head_init(&ppp->mrq);
#endif /* CONFIG_PPP_MULTILINK */ #endif /* CONFIG_PPP_MULTILINK */
ppp->dev = dev; ppp->dev = dev;
dev->init = ppp_net_init;
sprintf(dev->name, "ppp%d", unit);
dev->priv = ppp; dev->priv = ppp;
dev->destructor = free_netdev;
rtnl_lock(); dev->hard_start_xmit = ppp_start_xmit;
ret = register_netdevice(dev); dev->get_stats = ppp_net_stats;
rtnl_unlock(); dev->do_ioctl = ppp_net_ioctl;
ret = -EEXIST;
down(&all_ppp_sem);
if (unit < 0)
unit = cardmap_find_first_free(all_ppp_units);
else if (cardmap_get(all_ppp_units, unit) != NULL)
goto out2; /* unit already exists */
/* Initialize the new ppp unit */
ppp->file.index = unit;
sprintf(dev->name, "ppp%d", unit);
ret = register_netdev(dev);
if (ret != 0) { if (ret != 0) {
printk(KERN_ERR "PPP: couldn't register device %s (%d)\n", printk(KERN_ERR "PPP: couldn't register device %s (%d)\n",
dev->name, ret); dev->name, ret);
goto err_unlock; goto out2;
} }
atomic_inc(&ppp_unit_count); atomic_inc(&ppp_unit_count);
...@@ -2323,14 +2317,13 @@ ppp_create_interface(int unit, int *retp) ...@@ -2323,14 +2317,13 @@ ppp_create_interface(int unit, int *retp)
*retp = 0; *retp = 0;
return ppp; return ppp;
err_unlock: out2:
up(&all_ppp_sem); up(&all_ppp_sem);
err: free_netdev(dev);
*retp = ret; out1:
if (ppp)
kfree(ppp); kfree(ppp);
if (dev) out:
kfree(dev); *retp = ret;
return NULL; return NULL;
} }
...@@ -2361,8 +2354,10 @@ static void ppp_shutdown_interface(struct ppp *ppp) ...@@ -2361,8 +2354,10 @@ static void ppp_shutdown_interface(struct ppp *ppp)
ppp->dev = 0; ppp->dev = 0;
ppp_unlock(ppp); ppp_unlock(ppp);
/* This will call dev_close() for us. */ /* This will call dev_close() for us. */
if (dev) if (dev) {
unregister_netdev(dev); unregister_netdev(dev);
free_netdev(dev);
}
cardmap_set(&all_ppp_units, ppp->file.index, NULL); cardmap_set(&all_ppp_units, ppp->file.index, NULL);
ppp->file.dead = 1; ppp->file.dead = 1;
ppp->owner = NULL; ppp->owner = NULL;
......
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