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

[wan hdlc] kill embedding of struct net_device

Now we can kill the embedding of net_device into hdlc_device.  Indeed,
all instances of hdlc_device are created by alloc_hdlcdev() and nothing
uses hdlc->netdev directly.  So we can
        * remove hdlc->netdev
        * have alloc_hdlcdev() implemented via alloc_netdev() with the rest
of hdlc_device as private part of net_device.
        * replace free_hdlcdev() with free_netdev().
        * have dev_to_hdlc(dev) simply return netdev_priv(dev).
parent 705ddf60
......@@ -287,7 +287,7 @@ static void c101_destroy_card(card_t *card)
release_mem_region(card->phy_winbase, C101_MAPPED_RAM_SIZE);
}
free_hdlcdev(card->dev);
free_netdev(card->dev);
kfree(card);
}
......
......@@ -699,7 +699,7 @@ static void dscc4_free1(struct pci_dev *pdev)
pci_set_drvdata(pdev, NULL);
for (i = 0; i < dev_per_card; i++)
free_hdlcdev(root[i].dev);
free_netdev(root[i].dev);
kfree(root);
kfree(ppriv);
}
......@@ -885,7 +885,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr)
root[i].dev = alloc_hdlcdev(root + i);
if (!root[i].dev) {
while (i--)
free_hdlcdev(root[i].dev);
free_netdev(root[i].dev);
goto err_free_dev;
}
}
......@@ -953,7 +953,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr)
kfree(ppriv);
err_free_dev2:
for (i = 0; i < dev_per_card; i++)
free_hdlcdev(root[i].dev);
free_netdev(root[i].dev);
err_free_dev:
kfree(root);
err_out:
......
......@@ -1465,7 +1465,7 @@ fst_init_card ( struct fst_card_info *card )
printk_err ("Cannot register HDLC device for port %d"
" (errno %d)\n", i, -err );
for (j = i; j < card->nports; j++) {
free_hdlcdev(card->ports[j].dev);
free_netdev(card->ports[j].dev);
card->ports[j].dev = NULL;
}
card->nports = i;
......@@ -1534,7 +1534,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent )
hdlc_device *hdlc;
if (!dev) {
while (i--)
free_hdlcdev(card->ports[i].dev);
free_netdev(card->ports[i].dev);
printk_err ("FarSync: out of memory\n");
goto error_free_card;
}
......@@ -1651,7 +1651,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent )
error_free_ports:
for (i = 0; i < card->nports; i++)
free_hdlcdev(card->ports[i].dev);
free_netdev(card->ports[i].dev);
error_free_card:
kfree ( card );
return err;
......@@ -1686,7 +1686,7 @@ fst_remove_one ( struct pci_dev *pdev )
release_region ( card->pci_conf, 0x80 );
for (i = 0; i < card->nports; i++)
free_hdlcdev(card->ports[i].dev);
free_netdev(card->ports[i].dev);
kfree ( card );
}
......
......@@ -226,14 +226,33 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
}
}
static void hdlc_setup(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
dev->get_stats = hdlc_get_stats;
dev->change_mtu = hdlc_change_mtu;
dev->mtu = HDLC_MAX_MTU;
dev->type = ARPHRD_RAWHDLC;
dev->hard_header_len = 16;
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
hdlc->proto.id = -1;
hdlc->proto.detach = NULL;
hdlc->carrier = 1;
hdlc->open = 0;
spin_lock_init(&hdlc->state_lock);
}
struct net_device *alloc_hdlcdev(void *priv)
{
void *p = kmalloc(sizeof(hdlc_device), GFP_KERNEL);
if (p) {
memset(p, 0, sizeof(hdlc_device));
dev_to_hdlc(p)->priv = priv;
}
return p;
struct net_device *dev;
dev = alloc_netdev(sizeof(hdlc_device), "hdlc%d", hdlc_setup);
if (dev)
dev_to_hdlc(dev)->priv = priv;
return dev;
}
int register_hdlc_device(struct net_device *dev)
......
......@@ -325,9 +325,9 @@ static void n2_destroy_card(card_t *card)
if (card->io)
release_region(card->io, N2_IOPORTS);
if (card->ports[0].dev)
free_hdlcdev(card->ports[0].dev);
free_netdev(card->ports[0].dev);
if (card->ports[1].dev)
free_hdlcdev(card->ports[1].dev);
free_netdev(card->ports[1].dev);
kfree(card);
}
......
......@@ -3406,7 +3406,7 @@ static void cpc_init_card(pc300_t * card)
} else {
printk ("Dev%d on card(0x%08lx): unable to allocate i/f name.\n",
i + 1, card->hw.ramphys);
free_hdlcdev(dev);
free_netdev(dev);
continue;
}
}
......@@ -3653,7 +3653,7 @@ static void __devexit cpc_remove_one(struct pci_dev *pdev)
}
for (i = 0; i < card->hw.nchan; i++)
if (card->chan[i].d.dev);
free_hdlcdev(card->chan[i].d.dev);
free_netdev(card->chan[i].d.dev);
if (card->hw.irq)
free_irq(card->hw.irq, card);
kfree(card);
......
......@@ -557,7 +557,7 @@ static void wanxl_pci_remove_one(struct pci_dev *pdev)
for (i = 0; i < card->n_ports; i++)
if (card->__ports[i].dev)
free_hdlcdev(card->__ports[i].dev);
free_netdev(card->__ports[i].dev);
pci_set_drvdata(pdev, NULL);
kfree(card);
......
......@@ -96,7 +96,6 @@ typedef struct pvc_device_struct {
typedef struct hdlc_device_struct {
/* To be initialized by hardware driver */
struct net_device netdev; /* master net device - must be first */
struct net_device_stats stats;
/* used by HDLC layer to take control over HDLC device from hw driver*/
......@@ -191,15 +190,9 @@ void unregister_hdlc_device(struct net_device *dev);
struct net_device *alloc_hdlcdev(void *priv);
static inline void free_hdlcdev(struct net_device *dev)
{
kfree(dev);
}
static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev)
{
return (hdlc_device*)dev;
return netdev_priv(dev);
}
......
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