Skip to content

Commit 46f480e

Browse files
leitaokuba-moo
authored andcommitted
net: tuntap: Leverage core stats allocator
With commit 34d21de ("net: Move {l,t,d}stats allocation to core and convert veth & vrf"), stats allocation could be done on net core instead of in this driver. With this new approach, the driver doesn't have to bother with error handling (allocation failure checking, making sure free happens in the right spot, etc). This is core responsibility now. Remove the allocation in the tun/tap driver and leverage the network core allocation instead. Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 60d0642 commit 46f480e

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

drivers/net/tun.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -977,20 +977,15 @@ static int tun_net_init(struct net_device *dev)
977977
struct ifreq *ifr = tun->ifr;
978978
int err;
979979

980-
dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
981-
if (!dev->tstats)
982-
return -ENOMEM;
983-
984980
spin_lock_init(&tun->lock);
985981

986982
err = security_tun_dev_alloc_security(&tun->security);
987-
if (err < 0) {
988-
free_percpu(dev->tstats);
983+
if (err < 0)
989984
return err;
990-
}
991985

992986
tun_flow_init(tun);
993987

988+
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
994989
dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
995990
TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
996991
NETIF_F_HW_VLAN_STAG_TX;
@@ -1008,7 +1003,6 @@ static int tun_net_init(struct net_device *dev)
10081003
if (err < 0) {
10091004
tun_flow_uninit(tun);
10101005
security_tun_dev_free_security(tun->security);
1011-
free_percpu(dev->tstats);
10121006
return err;
10131007
}
10141008
return 0;
@@ -2317,7 +2311,6 @@ static void tun_free_netdev(struct net_device *dev)
23172311

23182312
BUG_ON(!(list_empty(&tun->disabled)));
23192313

2320-
free_percpu(dev->tstats);
23212314
tun_flow_uninit(tun);
23222315
security_tun_dev_free_security(tun->security);
23232316
__tun_set_ebpf(tun, &tun->steering_prog, NULL);

0 commit comments

Comments
 (0)