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

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>
This commit is contained in:
Eric Dumazet 2025-02-06 14:04:22 +00:00 committed by Simon Wunderlich
parent 9a006e72d3
commit 00b3553081
2 changed files with 14 additions and 12 deletions

View File

@ -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)

View File

@ -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;