Commit 23a12b14715e2dcd34dc8002927263ad3437344c

Authored by Stephen Hemminger
Committed by David S. Miller
1 parent 748ff68fad

ipip: convert to net_device_ops

Convert to network device ops. Needed to change to directly call
the init routine since two sides share same ops.  In the process
found by inspection a device ref count leak if register_netdevice failed.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 17 additions and 16 deletions Side-by-side Diff

... ... @@ -130,8 +130,8 @@
130 130 struct net_device *fb_tunnel_dev;
131 131 };
132 132  
133   -static int ipip_fb_tunnel_init(struct net_device *dev);
134   -static int ipip_tunnel_init(struct net_device *dev);
  133 +static void ipip_fb_tunnel_init(struct net_device *dev);
  134 +static void ipip_tunnel_init(struct net_device *dev);
135 135 static void ipip_tunnel_setup(struct net_device *dev);
136 136  
137 137 static DEFINE_RWLOCK(ipip_lock);
138 138  
... ... @@ -245,9 +245,10 @@
245 245 }
246 246  
247 247 nt = netdev_priv(dev);
248   - dev->init = ipip_tunnel_init;
249 248 nt->parms = *parms;
250 249  
  250 + ipip_tunnel_init(dev);
  251 +
251 252 if (register_netdevice(dev) < 0)
252 253 goto failed_free;
253 254  
254 255  
... ... @@ -691,12 +692,17 @@
691 692 return 0;
692 693 }
693 694  
  695 +static const struct net_device_ops ipip_netdev_ops = {
  696 + .ndo_uninit = ipip_tunnel_uninit,
  697 + .ndo_start_xmit = ipip_tunnel_xmit,
  698 + .ndo_do_ioctl = ipip_tunnel_ioctl,
  699 + .ndo_change_mtu = ipip_tunnel_change_mtu,
  700 +
  701 +};
  702 +
694 703 static void ipip_tunnel_setup(struct net_device *dev)
695 704 {
696   - dev->uninit = ipip_tunnel_uninit;
697   - dev->hard_start_xmit = ipip_tunnel_xmit;
698   - dev->do_ioctl = ipip_tunnel_ioctl;
699   - dev->change_mtu = ipip_tunnel_change_mtu;
  705 + dev->netdev_ops = &ipip_netdev_ops;
700 706 dev->destructor = free_netdev;
701 707  
702 708 dev->type = ARPHRD_TUNNEL;
703 709  
704 710  
... ... @@ -708,12 +714,10 @@
708 714 dev->features |= NETIF_F_NETNS_LOCAL;
709 715 }
710 716  
711   -static int ipip_tunnel_init(struct net_device *dev)
  717 +static void ipip_tunnel_init(struct net_device *dev)
712 718 {
713   - struct ip_tunnel *tunnel;
  719 + struct ip_tunnel *tunnel = netdev_priv(dev);
714 720  
715   - tunnel = netdev_priv(dev);
716   -
717 721 tunnel->dev = dev;
718 722 strcpy(tunnel->parms.name, dev->name);
719 723  
720 724  
... ... @@ -721,11 +725,9 @@
721 725 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
722 726  
723 727 ipip_tunnel_bind_dev(dev);
724   -
725   - return 0;
726 728 }
727 729  
728   -static int ipip_fb_tunnel_init(struct net_device *dev)
  730 +static void ipip_fb_tunnel_init(struct net_device *dev)
729 731 {
730 732 struct ip_tunnel *tunnel = netdev_priv(dev);
731 733 struct iphdr *iph = &tunnel->parms.iph;
... ... @@ -740,7 +742,6 @@
740 742  
741 743 dev_hold(dev);
742 744 ipn->tunnels_wc[0] = tunnel;
743   - return 0;
744 745 }
745 746  
746 747 static struct xfrm_tunnel ipip_handler = {
... ... @@ -793,7 +794,7 @@
793 794 goto err_alloc_dev;
794 795 }
795 796  
796   - ipn->fb_tunnel_dev->init = ipip_fb_tunnel_init;
  797 + ipip_fb_tunnel_init(ipn->fb_tunnel_dev);
797 798 dev_net_set(ipn->fb_tunnel_dev, net);
798 799  
799 800 if ((err = register_netdev(ipn->fb_tunnel_dev)))