diff mbox series

[1/3] net: dsa: introduce function dsa_tree_shutdown()

Message ID 20210909095324.12978-2-LinoSanfilippo@gmx.de
State New
Headers show
Series Fix for KSZ DSA switch shutdown | expand

Commit Message

Lino Sanfilippo Sept. 9, 2021, 9:53 a.m. UTC
Provide the function dsa_tree_shutdown() that can be called by DSA drivers
to tear down the DSA tree.
This is particularly useful for shutdown handlers to make sure that the DSA
tree is torn down (and thus all references to the master device are
released) before the master device is deregistered.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 include/net/dsa.h | 1 +
 net/dsa/dsa2.c    | 8 ++++++++
 2 files changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index f9a17145255a..7d4094faaa3a 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -1039,6 +1039,7 @@  static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr,
 }
 #endif
 
+void dsa_tree_shutdown(struct dsa_switch_tree *dst);
 void dsa_unregister_switch(struct dsa_switch *ds);
 int dsa_register_switch(struct dsa_switch *ds);
 struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 1b2b25d7bd02..0588581f6531 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1066,6 +1066,14 @@  static void dsa_tree_teardown(struct dsa_switch_tree *dst)
 	dst->setup = false;
 }
 
+void dsa_tree_shutdown(struct dsa_switch_tree *dst)
+{
+	mutex_lock(&dsa2_mutex);
+	dsa_tree_teardown(dst);
+	mutex_unlock(&dsa2_mutex);
+}
+EXPORT_SYMBOL_GPL(dsa_tree_shutdown);
+
 /* Since the dsa/tagging sysfs device attribute is per master, the assumption
  * is that all DSA switches within a tree share the same tagger, otherwise
  * they would have formed disjoint trees (different "dsa,member" values).