[PATCH] net: tipc: add net device refcount tracker for bearer
From: yang.yang29
Date: Fri Aug 04 2023 - 05:00:26 EST
From: xu xin <xu.xin16@xxxxxxxxxx>
Add net device refcount tracker to the struct tipc_bearer.
Signed-off-by: xu xin <xu.xin16@xxxxxxxxxx>
Reviewed-by: Yang Yang <yang.yang.29@xxxxxxxxxx>
Cc: Kuang Mingfu <kuang.mingfu@xxxxxxxxxx>
---
net/tipc/bearer.c | 10 +++++-----
net/tipc/bearer.h | 1 +
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 2cde375477e3..01ffd1f2337a 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -426,15 +426,15 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
struct net_device *dev;
/* Find device with specified name */
- dev = dev_get_by_name(net, dev_name);
+ dev = netdev_get_by_name(net, dev_name, &b->devtracker, GFP_KERNEL);
if (!dev)
return -ENODEV;
if (tipc_mtu_bad(dev)) {
- dev_put(dev);
+ netdev_put(dev, &b->devtracker);
return -EINVAL;
}
if (dev == net->loopback_dev) {
- dev_put(dev);
+ netdev_put(dev, &b->devtracker);
pr_info("Enabling <%s> not permitted\n", b->name);
return -EINVAL;
}
@@ -445,7 +445,7 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
tipc_net_init(net, node_id, 0);
}
if (!tipc_own_id(net)) {
- dev_put(dev);
+ netdev_put(dev, &b->devtracker);
pr_warn("Failed to obtain node identity\n");
return -EINVAL;
}
@@ -479,7 +479,7 @@ void tipc_disable_l2_media(struct tipc_bearer *b)
dev_remove_pack(&b->pt);
RCU_INIT_POINTER(dev->tipc_ptr, NULL);
synchronize_net();
- dev_put(dev);
+ netdev_put(dev, &b->devtracker);
}
/**
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 41eac1ee0c09..1adeaf94aa62 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -174,6 +174,7 @@ struct tipc_bearer {
u16 encap_hlen;
unsigned long up;
refcount_t refcnt;
+ netdevice_tracker devtracker;
};
struct tipc_bearer_names {
--
2.15.2