From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, buytenh@wantstofly.org,
Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal
Date: Mon, 12 Jan 2015 13:57:42 -0800 [thread overview]
Message-ID: <1421099866-3184-5-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1421099866-3184-1-git-send-email-f.fainelli@gmail.com>
We were not doing anything while removing the dsa module, which means
that we were leaving dangling network devices without any sort of driver
backing them, leading to all sorts of crashes. Make sure that we do
cleanup the slave network devices, slave MII bus we created, and
unassign the master_netdev dsa_ptr to make the packet processing go
through the regulard Ethernet receive path.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa.c | 19 +++++++++++++++++++
net/dsa/dsa_priv.h | 1 +
net/dsa/slave.c | 14 ++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index de77c83cfd9a..df7ec066ac64 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -316,10 +316,22 @@ out:
static void dsa_switch_destroy(struct dsa_switch *ds)
{
+ int i;
#ifdef CONFIG_NET_DSA_HWMON
if (ds->hwmon_dev)
hwmon_device_unregister(ds->hwmon_dev);
#endif
+
+ for (i = 0; i < DSA_MAX_PORTS; i++) {
+ if (!(ds->phys_port_mask & (1 << i)))
+ continue;
+
+ dsa_slave_destroy(ds->ports[i]);
+ }
+
+ mdiobus_unregister(ds->slave_mii_bus);
+ mdiobus_free(ds->slave_mii_bus);
+ kfree(ds);
}
#ifdef CONFIG_PM_SLEEP
@@ -754,6 +766,13 @@ static int dsa_remove(struct platform_device *pdev)
dsa_switch_destroy(ds);
}
+ dst->master_netdev->dsa_ptr = NULL;
+ /* If we used a tagging format that doesn't have an ethertype
+ * field, make sure that all packets from this point get sent
+ * without the tag and go through the regular receive path.
+ */
+ wmb();
+
dsa_of_remove(pdev);
return 0;
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 1397b2894c1f..1773b2a20d90 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -61,6 +61,7 @@ void dsa_slave_mii_bus_init(struct dsa_switch *ds);
struct net_device *dsa_slave_create(struct dsa_switch *ds,
struct device *parent,
int port, char *name);
+void dsa_slave_destroy(struct net_device *slave_dev);
int dsa_slave_suspend(struct net_device *slave_dev);
int dsa_slave_resume(struct net_device *slave_dev);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 515569ffde8a..043cffcb1a3a 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -690,3 +690,17 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
return slave_dev;
}
+
+void dsa_slave_destroy(struct net_device *slave_dev)
+{
+ struct dsa_slave_priv *p = netdev_priv(slave_dev);
+
+ if (p->phy) {
+ /* Prevent further updates */
+ fixed_phy_set_link_update(p->phy, NULL);
+ phy_disconnect(p->phy);
+ }
+
+ unregister_netdev(slave_dev);
+ free_netdev(slave_dev);
+}
--
2.1.0
next prev parent reply other threads:[~2015-01-12 21:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 1/8] net: dsa: add missing netdevice.h include Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 2/8] net: dsa: make module builds work Florian Fainelli
2015-01-13 21:38 ` David Miller
2015-01-13 22:27 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 3/8] net: phy: fixed: allow setting no update_link callback Florian Fainelli
2015-01-12 21:57 ` Florian Fainelli [this message]
2015-01-13 13:31 ` [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal Sergei Shtylyov
2015-01-12 21:57 ` [PATCH net-next 5/8] net: dsa: allow switch drivers to cleanup their resources Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 6/8] net: dsa: bcm_sf2: factor interrupt disabling in a function Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 7/8] net: dsa: bcm_sf2: cleanup resources in remove callback Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 8/8] net: dsa: free distributed switch tree pointer in dsa_remove Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1421099866-3184-5-git-send-email-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=buytenh@wantstofly.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).