[PATCH net-next v7 3/3] net: ethtool: netlink: Use netdev_hold for dumpit() operations

Maxime Chevallier
2025-04-22T18:33:37Z

Move away from dev_hold and use netdev_hold with a local reftracker when
performing a DUMP on each netdev.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
net/ethtool/netlink.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index 8ccc6957295d..9f08e9d9ed21 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -601,18 +601,19 @@ static int ethnl_default_dumpit(struct sk_buff *skb,
{
struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
struct net *net = sock_net(skb->sk);
+ netdevice_tracker dev_tracker;
struct net_device *dev;
int ret = 0;

rcu_read_lock();
for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
- dev_hold(dev);
+ netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
rcu_read_unlock();

ret = ethnl_default_dump_one(skb, dev, ctx, genl_info_dump(cb));

rcu_read_lock();
- dev_put(dev);
+ netdev_put(dev, &dev_tracker);

if (ret < 0 && ret != -EOPNOTSUPP) {
if (likely(skb->len))
--
2.49.0