netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <yang.yang29@zte.com.cn>
To: <davem@davemloft.net>
Cc: <dsahern@kernel.org>, <edumazet@google.com>, <kuba@kernel.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] udp_tunnel_nic: add net device refcount tracker
Date: Fri, 4 Aug 2023 16:49:46 +0800 (CST)	[thread overview]
Message-ID: <202308041649468563730@zte.com.cn> (raw)

From: xu xin <xu.xin16@zte.com.cn>

Add net device refcount tracker to udp_tunnel_nic.c.

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
Cc: Kuang Mingfu <kuang.mingfu@zte.com.cn>
---
 net/ipv4/udp_tunnel_nic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/udp_tunnel_nic.c b/net/ipv4/udp_tunnel_nic.c
index 029219749785..ce8f5c82b0a1 100644
--- a/net/ipv4/udp_tunnel_nic.c
+++ b/net/ipv4/udp_tunnel_nic.c
@@ -55,6 +55,9 @@ struct udp_tunnel_nic {
  */
 static struct workqueue_struct *udp_tunnel_nic_workqueue;

+/* To track netdev_hold and netdev_put */
+static netdevice_tracker udp_tunnel_nic_devtracker;
+
 static const char *udp_tunnel_nic_tunnel_type_name(unsigned int type)
 {
 	switch (type) {
@@ -825,7 +828,7 @@ static int udp_tunnel_nic_register(struct net_device *dev)
 	}

 	utn->dev = dev;
-	dev_hold(dev);
+	netdev_hold(dev, &udp_tunnel_nic_devtracker, GFP_KERNEL);
 	dev->udp_tunnel_nic = utn;

 	if (!(info->flags & UDP_TUNNEL_NIC_INFO_OPEN_ONLY))
@@ -879,7 +882,7 @@ udp_tunnel_nic_unregister(struct net_device *dev, struct udp_tunnel_nic *utn)
 	udp_tunnel_nic_free(utn);
 release_dev:
 	dev->udp_tunnel_nic = NULL;
-	dev_put(dev);
+	netdev_put(dev, &udp_tunnel_nic_devtracker);
 }

 static int
-- 
2.15.2

             reply	other threads:[~2023-08-04  8:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04  8:49 yang.yang29 [this message]
2023-08-04 10:42 ` [PATCH] udp_tunnel_nic: add net device refcount tracker Eric Dumazet
2023-08-05  6:27   ` xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202308041649468563730@zte.com.cn \
    --to=yang.yang29@zte.com.cn \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).