Skip to contentSkip to conversation

batman-adv: adopt netdev_hold() / netdev_put()

PATCH In review Eric Dumazet 2 participants 3 messages Feb 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 batman-adv: adopt netdev_hold() / netdev_put()

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

---
 net/batman-adv/hard-interface.c | 14 +++++---------
 net/batman-adv/types.h          |  3 +++
 2 files changed, 8 insertions(+), 9 deletions(-)
net/batman-adv/hard-interface.c +5 -9
index 96a412beab2de9069c0f88e4cd844fbc0922aa18..9a3ae567eb12d0c65b25292d020462b6ad60b699 100644
@@ -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);
 }
@@ -875,15 +875,16 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	ASSERT_RTNL();
 
 	if (!batadv_is_valid_iface(net_dev))
-		goto out;
+		return NULL;
 
-	dev_hold(net_dev);
 
 	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)
net/batman-adv/types.h +3 -0
index f491bff8c51b8bf68eb11dbbeb1a434d446c25f0..a73fc3ab7dd28ae2c8484c0d198a15437d49ea73 100644
@@ -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;
 
Signature · 1 line
2.48.1.362.g079036d154-goog
#1 lore raw
Quoted 59 lines · Eric Dumazet

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

---
  net/batman-adv/hard-interface.c | 14 +++++---------
  net/batman-adv/types.h          |  3 +++
  2 files changed, 8 insertions(+), 9 deletions(-)
net/batman-adv/hard-interface.c +5 -9
index 96a412beab2de9069c0f88e4cd844fbc0922aa18..9a3ae567eb12d0c65b25292d020462b6ad60b699 100644
@@ -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);
  }
@@ -875,15 +875,16 @@ batadv_hardif_add_interface(struct net_device *net_dev)
  	ASSERT_RTNL();
 
  	if (!batadv_is_valid_iface(net_dev))
-		goto out;
+		return NULL;
 
-	dev_hold(net_dev);
 
  	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)
net/batman-adv/types.h +0 -0
index f491bff8c51b8bf68eb11dbbeb1a434d446c25f0..a73fc3ab7dd28ae2c8484c0d198a15437d49ea73 100644

net/batman-adv/types.h struct batadv_hard_iface { · line 190

Quoted 5 lines
net/batman-adv/types.h +2 -0
@@ -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;

There are two blanks between type and member name. Is that intended?

net/batman-adv/types.h struct batadv_hard_iface { · line 194

Quoted 4 lines
net/batman-adv/types.h +1 -0
+
  	/** @refcount: number of contexts the object is used */
  	struct kref refcount;
 

We also have hard_iface->soft_iface storing a pointer to the soft_iface (batX) netdev.

How about converting that to netdev_put/hold as well?
See batadv_hardif_enable_interface() / batadv_hardif_disable_interface()

Best Regards,

Signature · 1 line
Antonio Quartulli
#2 lore raw
Quoted 64 lines · Antonio Quartulli
Quoted 62 lines · Eric Dumazet

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

---
  net/batman-adv/hard-interface.c | 14 +++++---------
  net/batman-adv/types.h          |  3 +++
  2 files changed, 8 insertions(+), 9 deletions(-)
net/batman-adv/hard-interface.c +5 -9
index 96a412beab2de9069c0f88e4cd844fbc0922aa18..9a3ae567eb12d0c65b25292d020462b6ad60b699 100644
@@ -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);
  }
@@ -875,15 +875,16 @@ batadv_hardif_add_interface(struct net_device *net_dev)
      ASSERT_RTNL();
 
      if (!batadv_is_valid_iface(net_dev))
-             goto out;
+             return NULL;
 
-     dev_hold(net_dev);
 
      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)
net/batman-adv/types.h +0 -0
index f491bff8c51b8bf68eb11dbbeb1a434d446c25f0..a73fc3ab7dd28ae2c8484c0d198a15437d49ea73 100644
@@ -186,6 +186,9 @@ struct batadv_hard_iface {
      /** @net_dev: pointer to the net_device */
      struct net_device *net_dev;
 
Quoted 4 lines

net/batman-adv/types.h struct batadv_hard_iface { · line 190

Quoted 2 lines
net/batman-adv/types.h +2 -0
+     /** @dev_tracker device tracker for @net_dev */
+     netdevice_tracker  dev_tracker;

There are two blanks between type and member name. Is that intended?

Not intended. Also a : is missing :

I can submit a V2 if you want, or feel free to make the changes.

net/batman-adv/types.h +0 -0
index a73fc3ab7dd28ae2c8484c0d198a15437d49ea73..8ac061379b6f72ef7f1d4e191888db2cc56376da

100644

net/batman-adv/types.h +2 -2
@@ -186,8 +186,8 @@ 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;
+       /** @dev_tracker: device tracker for @net_dev */
+       netdevice_tracker dev_tracker;
 
        /** @refcount: number of contexts the object is used */
        struct kref refcount;
Quoted 6 lines

net/batman-adv/types.h struct batadv_hard_iface { · line 194

Quoted 5 lines
net/batman-adv/types.h +1 -0
+
      /** @refcount: number of contexts the object is used */
      struct kref refcount;
 
Quoted 6 lines

We also have hard_iface->soft_iface storing a pointer to the soft_iface (batX) netdev.

How about converting that to netdev_put/hold as well?
See batadv_hardif_enable_interface() / batadv_hardif_disable_interface()

Sure, feel free to submit a patch for this one as well.

Thanks.