Skip to content

Commit 3b5933e

Browse files
leitaokuba-moo
authored andcommitted
net: loopback: Do not allocate lstats explicitly
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 loopback driver and leverage the network core allocation instead. Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Sabrina Dubroca <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 035ec29 commit 3b5933e

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

drivers/net/loopback.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,13 @@ static const struct ethtool_ops loopback_ethtool_ops = {
141141

142142
static int loopback_dev_init(struct net_device *dev)
143143
{
144-
dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
145-
if (!dev->lstats)
146-
return -ENOMEM;
147144
netdev_lockdep_set_classes(dev);
148145
return 0;
149146
}
150147

151148
static void loopback_dev_free(struct net_device *dev)
152149
{
153150
dev_net(dev)->loopback_dev = NULL;
154-
free_percpu(dev->lstats);
155151
}
156152

157153
static const struct net_device_ops loopback_ops = {
@@ -191,6 +187,7 @@ static void gen_lo_setup(struct net_device *dev,
191187
dev->header_ops = hdr_ops;
192188
dev->netdev_ops = dev_ops;
193189
dev->needs_free_netdev = true;
190+
dev->pcpu_stat_type = NETDEV_PCPU_STAT_LSTATS;
194191
dev->priv_destructor = dev_destructor;
195192

196193
netif_set_tso_max_size(dev, GSO_MAX_SIZE);

0 commit comments

Comments
 (0)