B.A.T.M.A.N Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Wunderlich <sw@simonwunderlich.de>
To: kuba@kernel.org, davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Eric Dumazet <edumazet@google.com>,
	Sven Eckelmann <sven@narfation.org>,
	Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH 03/10] batman-adv: adopt netdev_hold() / netdev_put()
Date: Thu, 13 Mar 2025 17:45:12 +0100	[thread overview]
Message-ID: <20250313164519.72808-4-sw@simonwunderlich.de> (raw)
In-Reply-To: <20250313164519.72808-1-sw@simonwunderlich.de>

From: Eric Dumazet <edumazet@google.com>

Add a device tracker to struct batadv_hard_iface to help
debugging of network device refcount imbalances.

Signed-off-by: Eric Dumazet <edumazet@google.com>
[sven@narfation.org: fix kernel-doc, adopt for softif reference]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/hard-interface.c | 20 ++++++++------------
 net/batman-adv/types.h          |  6 ++++++
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 96a412beab2d..71b2236c0058 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -51,7 +51,7 @@ void batadv_hardif_release(struct kref *ref)
 	struct batadv_hard_iface *hard_iface;
 
 	hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
-	dev_put(hard_iface->net_dev);
+	netdev_put(hard_iface->net_dev, &hard_iface->dev_tracker);
 
 	kfree_rcu(hard_iface, rcu);
 }
@@ -728,6 +728,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 	kref_get(&hard_iface->refcount);
 
 	dev_hold(soft_iface);
+	netdev_hold(soft_iface, &hard_iface->softif_dev_tracker, GFP_ATOMIC);
 	hard_iface->soft_iface = soft_iface;
 	bat_priv = netdev_priv(hard_iface->soft_iface);
 
@@ -784,7 +785,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 	netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
 err_dev:
 	hard_iface->soft_iface = NULL;
-	dev_put(soft_iface);
+	netdev_put(soft_iface, &hard_iface->softif_dev_tracker);
 	batadv_hardif_put(hard_iface);
 	return ret;
 }
@@ -851,7 +852,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
 	/* delete all references to this hard_iface */
 	batadv_purge_orig_ref(bat_priv);
 	batadv_purge_outstanding_packets(bat_priv, hard_iface);
-	dev_put(hard_iface->soft_iface);
+	netdev_put(hard_iface->soft_iface, &hard_iface->softif_dev_tracker);
 
 	netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
 	batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
@@ -875,15 +876,15 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	ASSERT_RTNL();
 
 	if (!batadv_is_valid_iface(net_dev))
-		goto out;
-
-	dev_hold(net_dev);
+		return NULL;
 
 	hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
 	if (!hard_iface)
-		goto release_dev;
+		return NULL;
 
+	netdev_hold(net_dev, &hard_iface->dev_tracker, GFP_ATOMIC);
 	hard_iface->net_dev = net_dev;
+
 	hard_iface->soft_iface = NULL;
 	hard_iface->if_status = BATADV_IF_NOT_IN_USE;
 
@@ -909,11 +910,6 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	batadv_hardif_generation++;
 
 	return hard_iface;
-
-release_dev:
-	dev_put(net_dev);
-out:
-	return NULL;
 }
 
 static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 64a0cf4257ed..b3b4f71f6dec 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -186,6 +186,9 @@ struct batadv_hard_iface {
 	/** @net_dev: pointer to the net_device */
 	struct net_device *net_dev;
 
+	/** @dev_tracker: device tracker for @net_dev */
+	netdevice_tracker dev_tracker;
+
 	/** @refcount: number of contexts the object is used */
 	struct kref refcount;
 
@@ -201,6 +204,9 @@ struct batadv_hard_iface {
 	 */
 	struct net_device *soft_iface;
 
+	/** @softif_dev_tracker: device tracker for @soft_iface */
+	netdevice_tracker softif_dev_tracker;
+
 	/** @rcu: struct used for freeing in an RCU-safe manner */
 	struct rcu_head rcu;
 
-- 
2.39.5


  parent reply	other threads:[~2025-03-13 16:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 16:45 [PATCH 00/10] pull request for net-next: batman-adv 2025-03-13 Simon Wunderlich
2025-03-13 16:45 ` [PATCH 01/10] batman-adv: Start new development cycle Simon Wunderlich
2025-03-18 11:30   ` patchwork-bot+netdevbpf
2025-03-13 16:45 ` [PATCH 02/10] batman-adv: Drop batadv_priv_debug_log struct Simon Wunderlich
2025-03-13 16:45 ` Simon Wunderlich [this message]
2025-03-13 16:45 ` [PATCH 04/10] batman-adv: Add support for jumbo frames Simon Wunderlich
2025-03-13 16:45 ` [PATCH 05/10] batman-adv: Use consistent name for mesh interface Simon Wunderlich
2025-03-13 16:45 ` [PATCH 06/10] batman-adv: Limit number of aggregated packets directly Simon Wunderlich
2025-03-13 16:45 ` [PATCH 07/10] batman-adv: Switch to bitmap helper for aggregation handling Simon Wunderlich
2025-03-13 16:45 ` [PATCH 08/10] batman-adv: Use actual packet count for aggregated packets Simon Wunderlich
2025-03-13 16:45 ` [PATCH 09/10] batman-adv: Limit aggregation size to outgoing MTU Simon Wunderlich
2025-03-13 16:45 ` [PATCH 10/10] batman-adv: add missing newlines for log macros Simon Wunderlich

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=20250313164519.72808-4-sw@simonwunderlich.de \
    --to=sw@simonwunderlich.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sven@narfation.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