Skip to content

Commit

Permalink
net: introduce netdev_napi_exit()
Browse files Browse the repository at this point in the history
After 1b23cdb ("net: protect netdev->napi_list with netdev_lock()")
it makes sense to iterate through dev->napi_list while holding
the device lock.

Also call synchronize_net() at most one time.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250117232113.1612899-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed Jan 19, 2025
1 parent 12d5151 commit 185e5b8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -11568,6 +11568,22 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
}
EXPORT_SYMBOL(alloc_netdev_mqs);

static void netdev_napi_exit(struct net_device *dev)
{
if (!list_empty(&dev->napi_list)) {
struct napi_struct *p, *n;

netdev_lock(dev);
list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
__netif_napi_del_locked(p);
netdev_unlock(dev);

synchronize_net();
}

kvfree(dev->napi_config);
}

/**
* free_netdev - free network device
* @dev: device
Expand All @@ -11579,8 +11595,6 @@ EXPORT_SYMBOL(alloc_netdev_mqs);
*/
void free_netdev(struct net_device *dev)
{
struct napi_struct *p, *n;

might_sleep();

/* When called immediately after register_netdevice() failed the unwind
Expand All @@ -11602,10 +11616,7 @@ void free_netdev(struct net_device *dev)
/* Flush device addresses */
dev_addr_flush(dev);

list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
netif_napi_del(p);

kvfree(dev->napi_config);
netdev_napi_exit(dev);

ref_tracker_dir_exit(&dev->refcnt_tracker);
#ifdef CONFIG_PCPU_DEV_REFCNT
Expand Down

0 comments on commit 185e5b8

Please sign in to comment.