diff options
author | Eric Dumazet <edumazet@google.com> | 2021-12-14 16:09:33 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-12-15 16:07:04 +0100 |
commit | f1d9268e061863ead77b07f5a6807d063e28a1c2 (patch) | |
tree | ccbfc01d0e6644eded73757c9884eee9a6dd7326 /net/packet/af_packet.c | |
parent | Merge branch 'mlxsw-ipv6-underlay' (diff) | |
download | linux-f1d9268e061863ead77b07f5a6807d063e28a1c2.tar.xz linux-f1d9268e061863ead77b07f5a6807d063e28a1c2.zip |
net: add net device refcount tracker to struct packet_type
Most notable changes are in af_packet, tipc ones are trivial.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jon Maloy <jmaloy@redhat.com>
Cc: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet/af_packet.c')
-rw-r--r-- | net/packet/af_packet.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index a1ffdb48cc47..71854a16afbb 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3109,7 +3109,7 @@ static int packet_release(struct socket *sock) packet_cached_dev_reset(po); if (po->prot_hook.dev) { - dev_put(po->prot_hook.dev); + dev_put_track(po->prot_hook.dev, &po->prot_hook.dev_tracker); po->prot_hook.dev = NULL; } spin_unlock(&po->bind_lock); @@ -3217,18 +3217,25 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex, WRITE_ONCE(po->num, proto); po->prot_hook.type = proto; + dev_put_track(dev_curr, &po->prot_hook.dev_tracker); + dev_curr = NULL; + if (unlikely(unlisted)) { dev_put(dev); po->prot_hook.dev = NULL; WRITE_ONCE(po->ifindex, -1); packet_cached_dev_reset(po); } else { + if (dev) + netdev_tracker_alloc(dev, + &po->prot_hook.dev_tracker, + GFP_ATOMIC); po->prot_hook.dev = dev; WRITE_ONCE(po->ifindex, dev ? dev->ifindex : 0); packet_cached_dev_assign(po, dev); } } - dev_put(dev_curr); + dev_put_track(dev_curr, &po->prot_hook.dev_tracker); if (proto == 0 || !need_rehook) goto out_unlock; @@ -4138,7 +4145,8 @@ static int packet_notifier(struct notifier_block *this, if (msg == NETDEV_UNREGISTER) { packet_cached_dev_reset(po); WRITE_ONCE(po->ifindex, -1); - dev_put(po->prot_hook.dev); + dev_put_track(po->prot_hook.dev, + &po->prot_hook.dev_tracker); po->prot_hook.dev = NULL; } spin_unlock(&po->bind_lock); |