net: add net device refcount tracker to struct pneigh_entry

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Dumazet 2021-12-04 20:22:08 -08:00 committed by Jakub Kicinski
parent 85662c9f8c
commit 77a23b1f95
2 changed files with 5 additions and 4 deletions

View File

@ -174,6 +174,7 @@ struct pneigh_entry {
struct pneigh_entry *next;
possible_net_t net;
struct net_device *dev;
netdevice_tracker dev_tracker;
u32 flags;
u8 protocol;
u8 key[];

View File

@ -771,10 +771,10 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
write_pnet(&n->net, net);
memcpy(n->key, pkey, key_len);
n->dev = dev;
dev_hold(dev);
dev_hold_track(dev, &n->dev_tracker, GFP_KERNEL);
if (tbl->pconstructor && tbl->pconstructor(n)) {
dev_put(dev);
dev_put_track(dev, &n->dev_tracker);
kfree(n);
n = NULL;
goto out;
@ -806,7 +806,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
write_unlock_bh(&tbl->lock);
if (tbl->pdestructor)
tbl->pdestructor(n);
dev_put(n->dev);
dev_put_track(n->dev, &n->dev_tracker);
kfree(n);
return 0;
}
@ -839,7 +839,7 @@ static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
n->next = NULL;
if (tbl->pdestructor)
tbl->pdestructor(n);
dev_put(n->dev);
dev_put_track(n->dev, &n->dev_tracker);
kfree(n);
}
return -ENOENT;