Skip to content

Commit

Permalink
batman-adv: adopt netdev_hold() / netdev_put()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and Simon Wunderlich committed Feb 22, 2025
1 parent 9a006e7 commit 00b3553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
20 changes: 8 additions & 12 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions net/batman-adv/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down

0 comments on commit 00b3553

Please sign in to comment.