Skip to content

Commit 23a12b1

Browse files
Stephen Hemmingerdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 748ff68 commit 23a12b1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

net/ipv4/ipip.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ struct ipip_net {
130130
struct net_device *fb_tunnel_dev;
131131
};
132132

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);
135135
static void ipip_tunnel_setup(struct net_device *dev);
136136

137137
static DEFINE_RWLOCK(ipip_lock);
@@ -245,9 +245,10 @@ static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
245245
}
246246

247247
nt = netdev_priv(dev);
248-
dev->init = ipip_tunnel_init;
249248
nt->parms = *parms;
250249

250+
ipip_tunnel_init(dev);
251+
251252
if (register_netdevice(dev) < 0)
252253
goto failed_free;
253254

@@ -691,12 +692,17 @@ static int ipip_tunnel_change_mtu(struct net_device *dev, int new_mtu)
691692
return 0;
692693
}
693694

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+
694703
static void ipip_tunnel_setup(struct net_device *dev)
695704
{
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;
700706
dev->destructor = free_netdev;
701707

702708
dev->type = ARPHRD_TUNNEL;
@@ -708,11 +714,9 @@ static void ipip_tunnel_setup(struct net_device *dev)
708714
dev->features |= NETIF_F_NETNS_LOCAL;
709715
}
710716

711-
static int ipip_tunnel_init(struct net_device *dev)
717+
static void ipip_tunnel_init(struct net_device *dev)
712718
{
713-
struct ip_tunnel *tunnel;
714-
715-
tunnel = netdev_priv(dev);
719+
struct ip_tunnel *tunnel = netdev_priv(dev);
716720

717721
tunnel->dev = dev;
718722
strcpy(tunnel->parms.name, dev->name);
@@ -721,11 +725,9 @@ static int ipip_tunnel_init(struct net_device *dev)
721725
memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
722726

723727
ipip_tunnel_bind_dev(dev);
724-
725-
return 0;
726728
}
727729

728-
static int ipip_fb_tunnel_init(struct net_device *dev)
730+
static void ipip_fb_tunnel_init(struct net_device *dev)
729731
{
730732
struct ip_tunnel *tunnel = netdev_priv(dev);
731733
struct iphdr *iph = &tunnel->parms.iph;
@@ -740,7 +742,6 @@ static int ipip_fb_tunnel_init(struct net_device *dev)
740742

741743
dev_hold(dev);
742744
ipn->tunnels_wc[0] = tunnel;
743-
return 0;
744745
}
745746

746747
static struct xfrm_tunnel ipip_handler = {
@@ -793,7 +794,7 @@ static int ipip_init_net(struct net *net)
793794
goto err_alloc_dev;
794795
}
795796

796-
ipn->fb_tunnel_dev->init = ipip_fb_tunnel_init;
797+
ipip_fb_tunnel_init(ipn->fb_tunnel_dev);
797798
dev_net_set(ipn->fb_tunnel_dev, net);
798799

799800
if ((err = register_netdev(ipn->fb_tunnel_dev)))

0 commit comments

Comments
 (0)