2022-03-11 21:42:24

by Ziyang Xuan (William)

[permalink] [raw]
Subject: [PATCH net-next 2/2] net: macvlan: add net device refcount tracker

Add net device refcount tracker to macvlan.

Signed-off-by: Ziyang Xuan <[email protected]>
---
drivers/net/macvlan.c | 4 ++--
include/linux/if_macvlan.h | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index d36af413e372..d6241ad66c0c 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -912,7 +912,7 @@ static int macvlan_init(struct net_device *dev)
port->count += 1;

/* Get macvlan's reference to lowerdev */
- dev_hold(lowerdev);
+ dev_hold_track(lowerdev, &vlan->dev_tracker, GFP_KERNEL);

return 0;
}
@@ -1181,7 +1181,7 @@ static void macvlan_dev_free(struct net_device *dev)
struct macvlan_dev *vlan = netdev_priv(dev);

/* Get rid of the macvlan's reference to lowerdev */
- dev_put(vlan->lowerdev);
+ dev_put_track(vlan->lowerdev, &vlan->dev_tracker);
}

void macvlan_common_setup(struct net_device *dev)
diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h
index 10c94a3936ca..b42294739063 100644
--- a/include/linux/if_macvlan.h
+++ b/include/linux/if_macvlan.h
@@ -21,6 +21,7 @@ struct macvlan_dev {
struct hlist_node hlist;
struct macvlan_port *port;
struct net_device *lowerdev;
+ netdevice_tracker dev_tracker;
void *accel_priv;
struct vlan_pcpu_stats __percpu *pcpu_stats;

--
2.25.1